P02c - Formatting Demo |
|
//P02c_formatting - Juan Marquez TR 1:00pm
//This program demonstrates that the compiler does not care
//about formatting. Programs should have comments throughout
//the program and should spaces between operators and operands
//and shoud be formatted using a block style, so that other
//programmers can easily read the code. Block style means
//that related code is indented to the same level.
#include <iostream>
using namespace std;
void main(){const double UNION_DUES=10.00,FICA_RATE=0.06,
FEDERAL_RATE(0.15),STATE_RATE=(0.05);int hours;
double rate, gross, fica, federal, state, netpay, netHourly;
//Set the decimal point to 2 positions
cout.setf(ios::fixed);cout.setf(ios::showpoint);
cout.precision(2);
//Display name and the input prompt
cout << "P02 - Juan Marquez TR 1:00pm \n\n";
cout << "Enter the hourly rate and the number of hours\n"
<< "worked on the same line, but separated by a space.\n"
<< "Press the enter key after entering both values."
<< endl << endl
<< "Enter the hourly rate and hours worked: ";
//Get the input values
cin >> rate >> hours;
//Calculate gross, taxes, netpay, and netHourly
gross = rate * hours;
fica = gross * FICA_RATE;
federal = gross * FEDERAL_RATE;
state = gross * STATE_RATE;
netpay = gross - (fica + federal + state + UNION_DUES);
netHourly = netpay / hours;
//Display the results - echo the input (rate and hours)
//Use the space bar between : and \t in labels instead of
//the tab key for accurate alignment.
cout << endl
<< "Hourly Rate: \t" << rate << endl
<< "Hours Worked:\t" << hours << endl
<< "Gross Pay: \t" << gross << endl
<< "FICA Tax: \t" << fica << " at " << FICA_RATE << endl
<< "Federal Tax: \t" << federal << " at " << FEDERAL_RATE << endl
<< "State Tax: \t" << state << " at " << STATE_RATE << endl
<< "Union Dues: \t" << UNION_DUES << endl
<< "Net Pay: \t" << netpay << endl
<< "Net Hourly: \t" << netHourly << endl;
cout << "\nThank you!\n\n";
}
//end of main
Sample Output:
P02 - Juan Marquez TR 1:00pm
Enter the hourly rate and the number of hours
worked on the same line, but separated by a space.
Press the enter key after entering both values.
Enter the hourly rate and hours worked: 9.25 25
Hourly Rate: 9.25
Hours Worked: 25
Gross Pay: 231.25
FICA Tax: 13.88 at 0.06
Federal Tax: 34.69 at 0.15
State Tax: 11.56 at 0.05
Union Dues: 10.00
Net Pay: 161.13
Net Hourly: 6.45
Thank you!
Press any key to continue