Average salaries over $10,000 - C++ Operator

C++ examples for Operator:Arithmetic Operator

Description

Average salaries over $10,000

Demo Code

#include <iostream>
using namespace std;
#include <iomanip>
int main()/*from  w  ww . jav  a  2 s .  c  om*/
{
   float month, year;      // Monthly and yearly salaries
   float avg=0.0, total=0.0;
   int count=0;
   do
   {
      cout << "What is the next monthly salary (-1) " << "to quit)? ";
      cin >> month;
      if ((year=month*12.00) <= 10000.00)  // Do not add
      {
         continue;
      }                   // low salaries.
      if (month < 0.0)
      {
         break;
      }           // Quit if user entered -1.
      count++;                 // Add 1 to valid counter.
      total += year;       // Add yearly salary to total.
   } while (month > 0.0);
   avg = total / (float)count;         // Compute average.
   cout << "\n\nThe average of high salaries " << "is $" << setprecision(2) << avg;
   return 0;
}

Result


Related Tutorials