# Array question

• 10-27-2005
Karmachrome
Array question
Hello there-

I'm drawing a blank here with this problem: create an array of grades based on user input, add up the scores and return a letter grade. Anyhoo...what I can't seem to figure out is what the best way to create this array. I would like the user to be able to add each score one at a time ("87", "78", "100", "97"...) until the Enter key is pressed.

Any help is extremely appreciated!!!
• 10-27-2005
ssharish2005
well, here is simple algorithm
Code:

```integer scorearray; do {       prompt user to enter score       get val       scoresarray <- val }while val not equal to '\n'; find the sum of all the scoresarray grade <-- findgrade(send the sum); output grade```

ssharish2005
• 10-27-2005
cwr
Presumably it's an assignment. Does the assignment mention a maximum number? In which case, create an array of N grades, then have it not allow the user enter more than N values.

If it truly has to be of arbitrary length, you could use a pointer and realloc, or ask the user how many grades they will enter, then malloc to that amount.

Finally, you could use a linked list or something, but that's somewhat overkill for this.
• 10-27-2005
Karmachrome
Thank you both.
This is what I had in the meantime - I think I'm on the right track.

Code:

```do         {         printf        ("\nPlease enter assignments scores, one at a time. Press Enter key when done:");         scanf        (  "%i", aScore);         }        while ('\n'!=getchar());```
• 10-27-2005
nonpuz
Code:

```int grades[100]={0}, i=0; while(scanf("%d",&grades[i]) == 1 && i++<100);```
could be one solution...