I have to write a program for class and it is suppose to read in an unknown number of employee records from a text file and each employee string has 47 characters, which includes name, employee number and hours worked, rate, overtime, and a few other variables.
The problem I am having is they are all read in as strings. I can output all of them to the screen no problem but he wants us to calculate:
gross pay = hours * rate + overtime * 1.5
which mean i need to convert my string to an int to do the calculations so i can cout my answer.
also we must calculate net pay = gross - deductions;
and a few other calculations, when i convert it it ends up printing the same output 20 times, and i need the math done but seperate answers for each calculation for each like
every line it does calculations for i need it to spit out an answer and it seems just replace the output reached about it.
Any assistance you can give me with my program would be great and I would really appreciate it.
This is what i have so far.
string info, name, hours, rate, depend, otime;
stringstream sshours, ssrate, ssdepend, ssotime;
double gross, hour, rat, depen, otim, fedtax, fica, ctax, udues, net, overtime;
int count = 0;
while (! infile)
{
cout << "Error opening file " << endl;
exit(1);
}
while (getline (infile, info))
{
string name = info;
string last, first, city, uni, empnum, depend, hours, rate, otime;
if ( count < 21, count ++)
{
last = name.substr(0,14);
first = name.substr(15,10);
city = name.substr(25,1);
uni = name.substr(26,1);
empnum = name.substr(27,5);
hours = name.substr(32,4);
sshours << hours;
sshours >> hour;
rate = name.substr(36,5);
ssrate << rate;
ssrate >> rat;
depend = name.substr(41,2);
ssrate << depend;
ssrate >> depen;
otime = name.substr(43,4);
ssrate << otime;
ssrate >> otim;
gross = (hour * rat);
cout << fixed << showpoint << setprecision(2);
cout << gross << endl;
}
}