Return to Topic Menu | Computer Science Main Page | MathBits.com  | Terms of Use

Demo "if" Statement

/*This program calculates weekly pay for fast-food managers.  The pay rate is $14.10 per hour.  In addition, if total sales exceed $9400 a week, the manager receives a $100 bonus for that week.*/

#inlcude <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
#include "apstring.cpp"

int main(void)
{
     system("CLS"); 
     apstring name;           //declare apstring to hold name
     const int bonus = 100;    //bonus is set constant
     double hours, total, pay;

      //Print and underline the headings
     cout<< "\n\nManager Pay Calculation Program\n";
     cout<<"```````````````````````````````````````````````````\n\n";

     //Get information from user at keyboard
     cout<<"Enter manager's full name: ";
     getline(cin,name);
     cout<<"How many hours did " <<name<<" work?";
     cin>> hours;
     cout<<"What were the total weekly sales? ";
     cin>>total;

     pay = 14.1 * hours;     //compute base pay

     if (total > 9400)
    {                      
 
           pay += bonus;  //bonus only if sales above 9400
                                     //remember: pay = pay + bonus;

     }

     cout.setf(ios::fixed);
     cout.setf(ios::showpoint);
     cout << "\n\n" <<name << " made $"
             <<setprecision(2) << pay <<"."
             <<endl<<endl<<endl;

     return 0;
}

 

 Return to Topic Menu | Computer Science Main Page | MathBits.com  | Terms of Use