Using namespace std Write a C program that continuously req

Using namespace std ;

Write a C++ program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should print an appropriate message informing the user that an invalid grade has been entered, else grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered. Run the program and verify it using the appropriate data.

Solution

#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
   int ch;

  
   int total=0;
   int count=0;
  
   do
   {
       cout<<\"Enter grade\ \";
       cin>>ch;

       if(ch<0||ch>100)
       {
           cout<<\"invalid grade has been entered\ \";
          
       }
       else
       {
           total+=ch;
           count++;
       }
   }while(ch!=999);  

   cout<<\"Avearge is \"<<(float)total/count<<endl;
  
   return 0;
}

======================================================

akshay@akshay-Inspiron-3537:~/Chegg$ g++ three.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Enter grade
1
Enter grade
2
Enter grade
3
Enter grade
4
Enter grade
5
Enter grade
6
Enter grade
101
invalid grade has been entered
Enter grade
999
invalid grade has been entered
Avearge is 3.5

Using namespace std ; Write a C++ program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should
Using namespace std ; Write a C++ program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site