# Input student grades and report the # of students with A, B, C, & D.

• 09-12-2012
motaro15
Input student grades and report the # of students with A, B, C, & D.
Greetings,

I was given the task to create a program that:

1. Lets you input grades from only 10 students.
2. Prints a report with the number of students who got A, B, C, and Ds.

I've been trying my hardest to figure it out, I think I'm onto something but I just need a little push in the right direction, specially with the part where "grade" gets saved into the memory and then it is supposed to add to the counters of the grades A, B, C, and D respectively according to what the user has input.

If you can help me a little I'll appreciate it.

Code:

```#include <stdio.h>#include <stdlib.h> #include <conio.h> int main() {     //initialize variables     int grade;     int A = 0;     int B = 0;     int C = 0;     int D = 0;     int count = 0; printf( "Enter 10 student's grades:\n");     while ( count < 10 ) {         scanf("%i", &grade);         grade = getchar();             if ( grade >= 90){             A = A + 1;             }             else if ((grade >= 80) && (grade < 90)) {             B = B + 1;             }             else if ((grade >= 70) && (grade < 80)) {             C = C + 1;             }             else ((grade >= 1) && (grade < 70)); {             D = D + 1;             }         count = count+1;     }     printf( "%i students got A\n", &A);     printf( "%i students got B\n", &B);     printf( "%i students got C\n", &C);     printf( "%i students got D\n", &D); return 0; }```
• 09-12-2012
memcpy
Code:

```scanf("%i", &grade);         grade = getchar(); if ( grade >= 90){   /* etc.. */```
You're overwriting the actual grade with a newline character every time. Instead, use:

Code:

```scanf(" %i", &grade); if (grade >= 90) {  /* etc.. */```
• 09-12-2012
motaro15
Unfortunately I keep getting the same nasty results.

3 students got A
2 students got B, etc

I get:
2686740 students got A
2686736 students got B, etc

I wonder what went wrong....
• 09-12-2012
sana.iitkgp
Quote:

Originally Posted by motaro15
printf( "%i students got A\n", &A);
printf( "%i students got B\n", &B);
printf( "%i students got C\n", &C);
printf( "%i students got D\n", &D);

[/CODE]

In these printf statements you are printing address of A not value of A.
Just remove the '&' before every variable in these printf statements.
You'll get the actual result.
• 09-12-2012
sana.iitkgp
One more thing,

Code:

```else ((grade >= 1) && (grade < 70)); {             D = D + 1;             }```
This is wrong, because D=D+1 is getting executed every time as you have ';' at the end of else statement.
You can write like this
Code:

`else D = D + 1;`
• 09-12-2012
motaro15
Holy cow! it worked!
I didn't know the difference between an address and a value of a variable, now I know.

Thanks sana.iitkgp and memcpy for your help
:D