hello guys
*write a program that will calculate the average of an unknown number of students.
*your program should validate the grades to be between 0 and 100.
*there are 5 grades to be entered and averaged .
*the program should enter the grades using a for loop the calculate and print the average for that student .
*the program should continue until the user decided to stop the program.

test data
student 1 : 100 ,100, 100, 100 ,100 ave:100
student 2 :90, 95, 80, 88, 90 ave:88.6
student 3 :75, 89, 87, 79, 80 ave:82.0
student 4 : 101, 99, 89, 90, 90 ave :93.6
student 5 : 76, 65, 68, 50, 72 ave: 66.2
student 6 :63, 51, 57, 60, 60 ave:58.2

once your program running correctly

* modify your program to count the numbers of A's, B's, C's, D's, and F's averages.
use if statement.
* print the counts within a table form.
table ex: i. A: 2 B : 3 C: 1 D: 0 F : 1

*print a histogram graphically representing the counts
i. A: **
ii. B: ***
iii. C: *
iv. D:
v. F: *

* modify your program to calculate and print the class average .

i'm using c forum

#include "stdafx.h"
#include<stdio.h>

int main(void)
{

And your question is?

## All 2 Replies

And your question is?

i know how to start but when i put my code to validate the grades to be between 0 and 100.it's doesn't work
this is my codes

``````#include "stdafx.h"
#include<stdio.h>

int main(void)
{
int DONE = 0;
int n;          //loop controller
int sum;
float average;  //calculated student average

while (DONE == 0)
{
sum = 0;//initalize sum

//Enter, verify and add 5 grades for this student

for(n = 1; n <= 5; ++n)
{
printf("Enter grade %i: ",n);

sum = sum + grade;
}

average = sum/5.0;
printf("Student Average: %.2f\n", average);

printf("Have you finished entering students?  1 = Yes  0 = No\n");
scanf("%i",&DONE);

}

printf("Have a nice day\n");

return 0;
}
``````

in this case the program runs good but when i put the code to validate the grades to be between 0 and 100. it's doesn't work

this is the coeds

``````// Do  While Sample.cpp : F2011  90.211  Week 9
/*Write an interactive program to average 5 grades for
an unknown number of students and print the results
rounded to 2 places.

Special Instructions:
You must include a stopping element.
The average should be clearly labeled.
*/
//

#include "stdafx.h"
#include<stdio.h>

int main(void)
{
int DONE = 0;
int n;          //loop controller
int sum;
float average;  //calculated student average

while (DONE == 0)
{
sum = 0;//initalize sum

//Enter, verify and add 5 grades for this student

for(n = 1; n <= 5; ++n)
{
printf("Enter grade %i: ",n);

if(grade < 0 || grade > 100)
printf("Invalid entry. . . Try again\n");

}while(grade < 0 || grade > 100);

sum = sum + grade;
}

average = sum/5.0;
printf("Student Average: %.2f\n", average);

printf("Have you finished entering students?  1 = Yes  0 = No\n");
scanf("%i",&DONE);

}

printf("Have a nice day\n");

return 0;}
``````