# Help with Array Program!

• 03-14-2002
ProgrammingDlux
Help with Array Program!
Hey Guys, I'm Having trouble with this program..

Assignment: ask how many students test scores user wants to input. Using loop structure, enter the test scores(must be at least 6). Program should count and print number of A's, B's, C's, D's, and F's. It should Average and find the largest of all scores.

MY PROBLEM: finding the largest of all scores...here is my code.

#include <iostream.h>
#include <stdlib.h>

main()
{int Num, C, Sum=0, Tot1=0, Tot2=0, Tot3=0, Tot4=0, Tot5=0, Tot6=0, Grade=0; float Avg;

cout<<"\nHow Many Test Scores do you want to enter?- You Must enter at least 6: ";cin>>Num;

if(Num<6)
{cout<<"\nSorry, You Must enter at least 6 Test Scores: ";}
else{
int Test[Num-1];

for(C=0;C<Num;C++)
{cout<<"\n Enter Score "<<C+1<<": "; cin>>Test[C];

if(Test[C]<=100 && Test[C]>=90)
else if(Test[C]<90 && Test[C]>=80)
else if(Test[C]<80 && Test[C]>=70)
else if(Test[C]<70 && Test[C]>=60)
else if(Test[C]<60 && Test[C]>=0)
else

Sum=Sum + Test[C];
}
Avg=Sum/Num;

cout<<"\n The Average is "<<Avg;
cout<<"\n There are "<<Tot1<<" A's ";
cout<<"\n There are "<<Tot2<<" B's ";
cout<<"\n There are "<<Tot3<<" C's ";
cout<<"\n There are "<<Tot4<<" D's ";
cout<<"\n There are "<<Tot5<<" F's ";
cout<<"\n There are "<<Tot6<<" Invalid Grades ";
}
system("PAUSE");
return 0;
}
• 03-14-2002
hk_mp5kpdw
This is wrong:

Quote:

int Test[Num-1];
Aside from the fact that the number of entries should be Num and not Num-1 you will need to use the new operator to dynamically declare the array like such:

Code:

`int *Test = new int[Num];`
Don't forget to call delete right after the last cout to free up the memory you allocated:

Code:

```        cout<<"\n There are "<<Tot5<<" F's ";         cout<<"\n There are "<<Tot6<<" Invalid Grades ";         delete [] Test;     }     system("PAUSE");```
• 03-14-2002
Prelude
>MY PROBLEM: finding the largest of all scores
Keep a maximum variable, test each score against that and if the score is greater, assign the score to the maximum variable. When you get to the end of the score the maximum variable will contain the largest score.

-Prelude