hello guys
grade book
*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)
{

Recommended Answers

All 3 Replies

You will want to have three functions, imo: getInput(), main() to process the data, and printIt() to make your output.

Right now, I'd start with those three functions, and make a file with the data, which your program can read when it starts, saving you the time and effort of filling in the data, each time the program needs to be restarted. (During coding, that will happen many times.)

If you're not comfortable with using a file for this, then use arrays and variables to hold the data for you, in the program, while testing is on-going.Remove it after it's working correctly, and you need to write the actual input code the assignment wants.

Using two array's is recommended. One for the students name, and one for their marks. So students[0] will have all his marks in the columns of the marks[0][0], marks[0][1], marks[0][2], etc. The student row number in the string array of students, will correspond with that students marks in the marks array row number.

Get started on that - no one is going to do your assignment for you, I assure you. When you get stuck on something, post up your code with code tags around it, and let us know what the problem is.

The more specific your description is, the better the answers will probably be.

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 grade; //user input grade
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);
scanf("%i",&grade);

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 grade; //user input grade
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);
scanf("%i",&grade);

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;
}

could you please help me in that???????

Maybe something like this.
You'll probably have to fix the "press any key" thing.

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

int main(void)
{
   int DONE = 0;
   int grade = 0; //user input grade
   int n = 0; //loop controller
   int sum = 0;
   float average = 0.0; //calculated student average
   char chrYesNo = 0;

   do
   {
      sum = 0;//initalize sum
      //Enter, verify and add 5 grades for this student
      for(n=0; n<5; n++)
      {
         printf("Enter grade %d: ",n);
         
         scanf("%i",&grade);

         if(grade < 0 || grade > 100)
         {
            printf("Invalid entry. . . Try again\n");
            n = n -1;
         }

         sum = sum + grade;
      }

      printf("Are you satisfied with those grades? [y/n]");
      
      while(!kbhit())
      {
      }
      
      getchar(); // clear the buffer
      chrYesNo = getchar();

      if( ('Y'==chrYesNo) || ('y'==chrYesNo))
      {
         DONE=1;
      }

   } while(DONE==0);

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

   puts("Have a nice day\nPress any key to exit");
   getchar();
   getchar();
   return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.