an application for a company that wants a breakdown of payroll by department. Input includes each employee’s last name, first name, department number, hourly salary, and number of hours worked. The output is a list of the seven departments in the company (numbered 1 through 7) and the total gross payroll (rate times hours) for each department.
I have used a for statement for the input, I know it wrong,but I cant figure out how to do it right
Here is what I have so far:
depnumber isn't used at all, so I would suggest using or removing it. Your last for loop has not brackets so it will only run the first line 7 times. You never declare totalrate or total hours to have only zeroes in them, so they will contain random numbers when you execute that line of code. Use getline(cin, str) for strings where str is the name of the string. Use cin.ignore(1, '\n') or cin.ignore() after each cin so that you can get rid of the newline character that will screw up every other input after it.
while(true){
cout<<"enter department number"<<endl;
cin>>depnumber;
cout<<"enter first name"<<endl;
cin>>firstname;
cout<<"enter last name"<<endl;
cin>>lastname;
cout<<"enter hourly salary"<<endl;
cin>>rate;
cout<<"enter hours worked"<<endl;
cin>>hours;
cout<<"the total gross payroll for department "<<depnumber<<" is: "<<rate*hours<<endl;
}
I dont know if this is what u want cause i dont understand what u are trying to do. So if this is not how u want it. Tell me :P