Hi everyone, I'm trying to do an array with size 100 initialized with values that's telling me how many students get the same grade by increasing everytime value of the given grade's index, for example : lets say I have inputted grade :80, then it must increase 1 in the countA[80]+=1; and if I have entered the grade 70..then it must increase 1 to the value of the countA[70]+=1....etc!, in other words the indexes of the array resembling the given grades and whenever there's a specific grade, then the code goes to the count[grade] and increasing it by 1.
how many grades I'm entering is related to the variable size that's decided by the user itself!
what I have done is that:
Code:
#define NUM_OF_GRADES 100
int main()
{
int countA[NUM_OF_GRADES]={0};
printf("Please enter the class size:\n");
scanf("%d",&size);
printf("Please enter first class grades:\n");
for (int i=0 ; i<size ; r++)
{
countA[scanf("%d\n",&grade)]++ ;
// here I'm going to the given grade as it's the index of the array countA and increasing the value of it by 1 then it means that this grade has been entered..etc.// }
printf("the class's grades") ;
Code:
for (int i=0 ; i<size ; r++)
{
printf("%d", countA[i]);
}
return 0;
}
I tried to print the array after I've inputted some grades but unfortunately it showed wrong printf, conversely to what expected!
can anyone please help me and suggest me why my code isn't working correctly????
thanks!