Site hosted by Angelfire.com: Build your free website today!

Program #6 

 

 


USING AN ‘if’ STATEMENT and ACCUMULATORS

This program will calculate a payroll chart for a business.

You will have three employees.  Ask the employee’s name, pay rate, and hours worked. You will do the same process three times (in the future we will use a loop that will let you do it for as many people as you want.)  As you process each person, calculate his or her pay like this…

            If they worked 40 or fewer hours their pay will be hours times pay rate

                        pay1=rate1*hours1;

If hours worked is over 40, they get paid overtime for every hour past 40 (regular pay for the first 40)

            pay1=40*rate+(hours-40)*rate*1.5;

This pay stuff needs to be done with an ‘if’ statement.

            if  (hours<=40) pay1=rate1*hours1;  (do another ‘if’ for over 40 hours)

Taxes will then be 30% of this gross amount.

Net pay=gross-taxes.

            tax1=pay1*.30; and net1=pay1-tax1;

You will need to accumulate the 3 pay amounts, 3 tax amounts and 3 net amounts.  This will be done like this…

            Initialize the three accumulators at top of program-

float paytotal=0, taxtotal=0, nettotal=0;

As you calculate each person’s pay, add to the three accumulators.

            paytotal=paytotal+pay1;

            taxtotal=taxtotal+tax1;

            nettotal=nettotal+net1;

Finally, print this chart…

                        PAYRATE CHART FOR MICROSOFT COMRPORATION

PAY RATE      HOURS           GROSS            TAXES            NET PAY        NAME

$12.45              30                     373.50              112.05              261.45              P-Diddy

$18.25              45                     866.88              260.06              606.82              Al Hamilton

$10.50              40                     420.00              126.00              294.00              Roland Chumley

 

Pay total: $1660.38

Tax total: $498.11

Net total: $1162.37                               

 
 

 

 

 

 

 

 

 

 


Suggestions for the order in which to write this program-

*Declare

Identifiers (paytotal, nettotal, taxtotal, pay1, pay2, pay3, hours1, hours2, hours3, tax1, tax2, tax3, name1, name2, name3, rate1, rate2, rate3, net1, net2, net3)

*Ask name1, rate1, hours1 (for name use cin.get(name, 80); cin.ignore(80, ‘\n’);

*Calculate tax1, net1

*Accumulate total pay, total tax, and total net

*Follow above for person two, then again for three

*Print chart (to get decimals correct, use setprecision(2) with cout.setf’s)