Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete C++ program to calculate the average grade for a student. Displ

ID: 3590842 • Letter: W

Question

Write a complete C++ program to calculate the average grade for a student. Display a prompt on the monitor ask a user: “ How many grades do you want to process? “. After user has entered how many grades he/she wants to process, create a loop that will allow the user to enter his/her grades ( grades should be in the range of 0 to 100, Your program should validate that grades entered are in the range of 0 to 100 and reject grades that are not in this range). After user has entered all of his/her grades your program should calculate the average grades and display the average grades.

Explanation / Answer

// C++ program to calculate the average grade for a student

#include<iostream>
using namespace std;
int main()
{
   int number;           //to store number of grades to be processed
   int sum=0;
   cout<< " How many grades do you want to process? ";
   cin>>number;
   int grades[number];               //to store grades values
   cout<<"Enter "<<number<<" Grades in the range of ( 0 to 100 ):";
   for(int i=0;i<number;i++)
   {
       cin>>grades[i];               //storing grades values
       if(!(grades[i]>=0 && grades[i]<=100))
       {
           cout<<" Invalid Grade Value.. ";
           cout<<"Please Enter this grade again :";
           cin>>grades[i];                   //taking invalid grade again
       }
       sum=sum+grades[i];                   //calculating sum of all the valid grades
   }
   cout<<" Entered Correct Grades are :";
   for(int i=0;i<number;i++)
   {
       cout<<" "<<grades[i];               //printing valid grades only
   }
   float avg=(float)sum/(float)number;                   //calculating average grades here
   cout<<" Average Grade is :"<<avg;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote