Adds grades and determines whether you earned an A. - C++ Statement

C++ examples for Statement:do while

Description

Adds grades and determines whether you earned an A.

Demo Code

#include <iostream>
using namespace std;
#include <iomanip>
int main()/*from   ww w.  j av  a  2  s  . c  o  m*/
{
   float total_grade=0.0;
   float grade;             // Holds individual grades.
   do
   {
      cout << "What is your grade? (-1 to end) ";
      cin >> grade;
      if (grade >= 0.0)
      {
         total_grade += grade;
      }        // Add to total.
   } while (grade >= 0.0);     // Quit when -1 entered.

   cout << "\n\nYou made a total of " << setprecision(1) << total_grade << " points\n";
   if (total_grade >= 450.00)
   {
      cout << "** You made an A!!";
   }
   return 0;
}

Result


Related Tutorials