Beginner in C++ GOING CRAZY WITH THIS PROGRAM!!

Ok.. So i manage to read and print the data.. But what I dont understand is how to attach it to id,rate,pay,hours.. can someone help me please im really stuck... THX

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
int hours,rate,age;
int x;
int str;
string shift;
ifstream infile;
infile.open("empfile.txt");


if (!infile)
{
cout << "unable to open file";

}


while (getline(infile, shift))
cout << shift << endl;

infile.close();




{


//where is base salary
double pay=0;
if(hours>40) pay=(hours-40)*1.5*rate +40*rate;
else pay=hours*rate;
double tax=0;
if(age>55) tax =0.20;
else tax =0.10;
}
return 0;
}


Read in groups of data bout employees of a company. Each group of data will contain an employees id numer, hours worked, rate of pay, and age ( the age will b an interger). A typical group data will be

643456 46.9 3.26 51


This means that employee 643456 worked 46.9 hours at 3.26 per hr nd he is 51 years old.


Print the original data as it is read in together with appropriate messages.
For each employee compute the employees base pay, which includes overtime ( paid at one and a half times the normal rate) for each hour over 40. For example, if an employee earning 20.00 per hr works for 48 hrs. then she will be paid for 40 hrs at her normal rate plus 8 extra hrs at 30.00. Print the base pay for the employee.
Then compute the tax paid by the employee, according to this formula: if the employee is 55 years old or older, then the employees pays tax at a rate of 20% of the base pay: if the employee is below 55 then the tax is 10% of the base pay. print the tax and the net pay after taxes.

after you print all of the info for an employee read the data for the next employee you must decide how to detect the end of the set of employees you should explain you choice in a comment.

after processing the last employee print a message saying that the payroll program is complete.

Heres is the data you should use when you sure the program is working correctly.

323456 42.0 3.00 54
783454 48.0 10.00 45
564789 37.0 6.00 59
230234 20.0 7.00 12
123987 50.0 12.00 55
347654 80.0 5.00 123
345267 30.0 23.00 74
467843 12.5 6.50 45
134267 67.3 11.25 58
312546 35.0 25.00 48


In addition to the above
1. print the employee number and age of the oldest employee.
2. print the employee number and taxes of the employee who paid the most in taxes. these names should be printed after the entire set of employees has been processed.
But what I dont understand is how to attach it to id,rate,pay,hours
What you need is an array like so int hours[100];

The best would be to tie them in a struct and then make an array of that struct but you can also have them as separate arrays.

To get the data from shift you can use stringstream:

http://www.cplusplus.com/reference/iostream/stringstream/

Like so:
1
2
3
4
5
6
7
8
9
10
#include <sstream>
...
int i = 0;
while (...)
{
stringstream ss(shift);
ss >> hour[i] >> ...;
...
i++;
}
Last edited on
Topic archived. No new replies allowed.