First compute the employee's gross pay. Gross pay is hours worked multiplied by hourly rate. We will assume (for
simplicity) that no employee will work more than 40.0 hours, therefore no overtime pay calculation is needed.
Next, compute the net pay. To do so, we must determine the amount of taxes to withhold. For simplicity we will
assume workers who make less than $300 have only 12% of their pay withheld for taxes. However, workers who
make at least $300, but less than $400 have 17% of their pay withheld for taxes. And finally, workers who make at
least $400 have 20% of their pay withheld for taxes.
You must have named constants for each of these dollar amounts and percentages, and you must use them in your
programming statements.
Finally, you must calculate these values for all the employees in the input file. Once you've computed all employees'
gross and net pays, print all data to the screen.
That the objective of the assignment, I was given an a example on how to display the output
CODE
Hours Rate Gross (Tax %) Net
-------------------------------
35.0 9.5 x x x
Im working it I have this incomplete code so far
CODE
//Reading a text file
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const double THREE_HUNDRED_TAX = 12;
const double THREE_FOUR_HUNDRED_TAX = 17;
const double FOUR_HUNDRED_TAX = 20;
const int THREEHUNDRED = 300;
const int FOURHUNDRED = 400;
int main ()
{
double hours1, rate1, hours2, rate2, hours3, rate3, hours4, rate4, hours5, rate5, gross1, gross2, gross3, gross4, gross5, net, tax, TaxHeld;
ifstream inFile;
inFile.open("pa3.input.txt");
inFile >>hours1>>rate1>>hours2>>rate2>>hours3>>rate3>>hours4>>rate4>>hours5>>rate5;
cout<< fixed << showpoint;
cout<< setprecision(2);
gross1=(hours1*rate1), gross2=(hours2*rate2), gross3=(hours3*rate3), gross4=(hours4*rate4), gross5=(hours5*rate5);
if (gross1, gross2, gross3, gross4, gross5 < THREEHUNDRED)
{
tax = THREE_HUNDRED_TAX;
TaxHeld = gross1*(THREE_HUNDRED_TAX /100);
net= TaxHeld - gross1;
cout<<net;
}
else if (gross1, gross2, gross3, gross4, gross5 >= THREEHUNDRED && gross1, gross2, gross3, gross4, gross5 < FOURHUNDRED)
{
tax = THREE_FOUR_HUNDRED_TAX;
}
else
{
tax = FOUR_HUNDRED_TAX;
}
inFile.close();
system ("Pause Screen");
return 0;
}
I dont like how its jumbled I want to clean it up I prefer it that way, also getting a bit stuck on how to format the output.
I am calling the input from a .txt file set up like this
35.0 9.75
40.0 10.25
The first hour is hours and second row is rate. I needed 5 lines of data, hence ten variable names hours1, rate1 and etc.
Also made constants for the tax % withheld
I am unsure how to formulate the if statement, I am sure I need one, to output it the way I show above.
Thanks, I just got a bit tired, not lazy.