C++ while statement Sum the numbers entered

Description

C++ while statement Sum the numbers entered

#include <iostream>
#include <iomanip>
using namespace std;
int main()/*from w  w  w .  ja  v a2 s . c o m*/
{
   const int MAXNUMS = 4;
   int count;
   double num, total;
   cout << "\nThis program will ask you to enter "
   << MAXNUMS << " numbers.\n";
   count = 1;
   total = 0;
   while (count <= MAXNUMS)
   {
      cout << "\nEnter a number: ";
      cin  >> num;
      total = total + num;
      cout << "The total is now " << setprecision(7) << total;
      count++;
   }
   cout << "\nThe final total is " << setprecision(7) << total << endl;
   return 0;
}



PreviousNext

Related