You are here:

C++/I need help with a C program please.


I'm a complete newbie to C programming and I need help writing a program. The program should do the following:

Prompt the user to select the number of grades he wishes to average.  Max points for each grade are 100.  Calculate the Average grade of all of the grades entered and display the final Average, the lowest and highest grades entered. This program should use a WHILE loop in its main loop.

Example program output:

How many grades do you wish to average: 5

Enter  Grade 1: 78.90

Enter  Grade 2: 43.25

Enter  Grade 3: 100

Enter  Grade 4: 78.54

Enter  Grade 5: 80.5


The average of the grades was 76.24

The highest grade entered was 100.00

The lowest grade entered was  43.25


So far I just have a program that will let me sum all the grades up, but I don't know how to make it sum as many grades as the user wishes and average them. I know that when the user is prompted to enter the number of grades he wishes to average, the total sum should be divided by whatever number the user entered. The program I've written to sum is as follows and the program for averaging grades should follow the same format such as using only #include<stdio.h> and int main():

#include <stdio.h>
int main(void)
   long num;
   long sum = 0L;
   int status;

   printf("Please enter an integer to be summed ";
   printf("(q to quit): ");
   status = scanf("%ld", &num);
   while (status == 1)
       sum = sum + num;
       printf("Please enter next integer (q to quit): ");
       status = scanf(%ld", &num);
   printf("Those integers sum to %ld. \n", sum);
   return 0

Any help you could offer would be much appreciated. You would be really helping me out and I would be sure to rate you highly for however little help that you can offer me.

Thanks again,

You are almost there.
Here is an outline of what you should do:

#include <stdio.h>

int main(void)
  int number_of_grades = 0 ;
  int number_entered_so_far = 0 ;
  int sum_of_grades = 0 ;
  int max_grade = 0 ;
  int min_grade = 100 ;
  double average_grade = 0.0 ;

         1. prompt the user to enter the number of grades
      to be processed by the program
      2. read the value into number_of_grades

  /* loop to read in number_of_grades grades */
  while( number_entered_so_far < number_of_grades )
     int current_grade = 0 ;
      1. prompt the user to enter a grade
      2. read the value into current_grade

      ++number_entered_so_far ;

      sum_of_grades += current_grade ;

     if( current_grade > max_grade )
        max_grade = current_grade ;

     if( current_grade < min_grade )
        min_grade = current_grade ;

  average_grade = (double)sum_of_grades / number_of_grades ;
       print out average_grade, min_grade, max_grade
  return 0 ;

>  I would be sure to rate you highly for however little help that you can offer me.
I strongly encourage you to rate the answers honestly based on your evaluation of their merit. A high rating by itself means little to me unless I know it is genuine. And it might mislead others who use the site.


All Answers

Answers by Expert:

Ask Experts




my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.


about 15 years or so

post graduate engineer

©2016 All rights reserved.