C++ cin read until certain value

Description

C++ cin read until certain value

#include <iostream>
using namespace std;
int main()// w w  w  .  ja v  a 2s.  c  om
{
   const int HIGHGRADE = 100;
   double grade, total;
   grade = 0;
   total = 0;
   cout << "\nTo stop entering grades, type in any number\n greater than 100.\n\n";
   while (grade <= HIGHGRADE)
   {
      total = total + grade;
      cout << "Enter a grade: ";
      cin  >> grade;
   }
   cout << "\nThe total of the grades is " << total << endl;
   return 0;
}



PreviousNext

Related