C++ float type Average salaries over $10,000

Description

C++ float type Average salaries over $10,000

#include <iostream>
using namespace std;
#include <iomanip.h>
int main()//  w  w  w.j  a v a2  s  .  c o  m
{
   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;
}



PreviousNext

Related