Thread: Student average grade program

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    3

    Student average grade program

    I've got this assignement and i dont really understand the question: Suppose there are 100 students in a class. You are asked to write a program that can accept the input of the students’ marks from the keyboard and calculate the class average and display it on the screen. Note that each mark is between 0 and 100.

    That's where i got so far:

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        double avg;
        int i,a,sum=0;
        for (int i = 0; i< 100; i++)
        {
             cout <<" Enter a mark:";
             cin >> a;
             while (a <0 || a >100)
             cout <<"Error";
             cin >> a;
         }
         {
             sum = sum +a ;
            }
             avg = sum / 100.0;
              cout <<" The avg of the class is: " << avg <<endl;
            }
    }
    Thanks for the help

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    The first step is to learn how to indent code.
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
      double avg;
      int i, a, sum = 0;
      for (int i = 0; i < 100; i++) {
        cout << " Enter a mark:";
        cin >> a;
        while (a < 0 || a > 100)
          cout << "Error";
        cin >> a;
      }
      {
        sum = sum + a;
      }
      avg = sum / 100.0;
      cout << " The avg of the class is: " << avg << endl;
    //}
    }
    So for example, you have an extra brace at line 20.
    The cin at line 13 is NOT part of your error correction loop input.
    The summation at line 16 is NOT part of your input loop.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2015
    Posts
    3
    Yes so that's what the question was asking me to do?

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I think you missed the mark. The problem statement said that there were 100 students, not 100 grades, so you probably calculated the wrong average. If every student has their own grades, the class average is going to be slightly different. I'm not your teacher though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. average grade program
    By fyu2 in forum C Programming
    Replies: 3
    Last Post: 05-25-2012, 01:11 AM
  2. Grade program average problem
    By Zaz in forum C Programming
    Replies: 1
    Last Post: 11-20-2009, 07:11 PM
  3. Student Roster & Grade Average
    By Surge in forum C Programming
    Replies: 10
    Last Post: 12-12-2006, 07:32 AM
  4. Student Grade Program
    By Vinod Menon in forum C Programming
    Replies: 1
    Last Post: 05-31-2004, 12:32 AM
  5. Student Grade Program
    By Vinod Menon in forum C Programming
    Replies: 5
    Last Post: 05-28-2004, 02:49 PM