How to stop an overloop output in a class? - c++

So I have an assignment for a class where I have to convert an employee payroll program into a class. I've completed that part and can even generate an output, but the problem starts there. The output keeps looping. I've had this problem before when I had an earlier program and the way I set the while loop was wrong. But this time, the while statement is fine, but the program still loops. I've corrected other errors but still cannot find this one.
Here is the code I've come up with:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;
class payroll {
ifstream fin;
char employeeid[12];
char firstname[20];
char lastname[20];
char SMH;
int SSN, hoursworked, overtimehours;
double hourlyrate, regularpay, overtimepay, grosspay, taxrate, taxamount, netpay, sum, average;
public:
payroll(){
fin.open("employee.txt");
}//CONSTRUCTOR
~payroll();
private:
void calcgrosspay() {
grosspay = regularpay + overtimepay;
if (hoursworked > 40) {
overtimehours = hoursworked - 40;
overtimepay = overtimehours * hourlyrate * 1.5;
regularpay = 40 * hourlyrate;
}//if
else {
overtimehours = 0;
overtimepay = 0;
regularpay = hoursworked * hourlyrate;
}//else
}//for
void calctax() {
if (grosspay >= 500) taxrate = .30;
else if (grosspay>200.00) taxrate = .20;
else taxrate = .10;
if (SMH == 'S' || SMH == 's')
taxrate = taxrate + .05;
taxamount = grosspay*taxrate;
}//for end of grosspay and set taxrate FOR
void calcNetpay() {
netpay = grosspay - taxamount;
}//end of calcnetpay function
void printheadings() {
cout << setw(49) << "-Payroll Report-" << endl;
cout << "------------------------------------------------------------------------------" << endl;
cout << "ID First Name Last Name Stat SSN HW HR OT OP GP Tax Net" << endl;
cout << "==============================================================================" << endl;
cout << "------------------------------------------------------------------------------" << endl;
}//printheadings
void printdata() {
setprecision(2);
cout << setw(14) << employeeid
<< setw(16) << firstname
<< setw(15) << lastname
<< setw(6) << SMH
<< setw(5) << SSN
<< setw(6) << hoursworked
<< setw(6) << hourlyrate
<< setw(8) << grosspay
<< setw(6) << taxrate
<< setw(9) << regularpay
<< setw(6) << overtimehours
<< setw(6) << overtimepay
<< setw(9) << netpay << endl;
}//print data
void payroll::findsum(int i) {
sum += netpay;
}
double payroll::findavg(double, int i) {
average = sum / i;
cout << endl << "The netpay average is " << average << endl;
return average;
}
public:
void printreport() {
int i = 0;
printheadings();
while (fin >> employeeid >> SMH >> SSN >> hoursworked >> hourlyrate >> firstname >> lastname)
{
calcgrosspay();
calctax();
calcNetpay();
printheadings();
printdata();
i++;
findsum(i);
}//while
findavg(sum, i);
}//print data report
}; // end of payroll class
payroll::~payroll() {
fin.close();
}//DESTRUCTOR
int main() {
payroll employee;
employee.printreport();
system("PAUSE");
}//main

Related

Total of an array using class object

How can I get the total of the grosspay of all five employees? I've tried everything including creating objects but none seem to work, also I must store all the data in one array called EmpData so I cannot change that. I require assistance. This is the code I've created and it runs and works properly so far.
#include<iostream>
using namespace std;
class Employee {
private:
double hourswrk;
double payrate;
double grosspay;
int empno;
char empname[20];
double netpay;
double tax;
double overt;
double overtime;
double taxdeduct;
public:
void getdetails();
void calculatepay();
void showdetails();
};
void Employee::getdetails()
{
cout << "\nEnter employee name:\n";
cin >> empname;
cout << "\nEnter employee number:\n";
cin >> empno;
cout << "Enter hours worked:";
cin >> hourswrk;
cout << "Enter rate of pay";
cin >> payrate;
}
void Employee::calculatepay()
{
tax = 0.25;
overt = 1.5;
if(hourswrk >= 60)
{
grosspay = 0;
netpay = 0;
taxdeduct = 0;
cout << "You have exceeded the amount of hours!";
}
else if(hourswrk <= 40)
{
grosspay = hourswrk * payrate;
}
else if(hourswrk > 40 && hourswrk < 60)
{
overtime = hourswrk - 40;
grosspay = overt * payrate*overtime + hourswrk * payrate;
}
taxdeduct = tax * grosspay;
netpay = grosspay - taxdeduct;
}
void Employee::showdetails()
{
cout << "Employee Payslip\n";
cout << "Name: " << empname;
cout << "Employee number:" << empno;
cout << "Basic Salary" << payrate;
cout << "Hours work" << hourswrk;
cout << "Grosspay" << grosspay;
cout << "Tax: " << taxdeduct;
cout << "Net Salary" << netpay;
cout << endl;
}
int main()
{
Employee EmpData[5];
int i;
double hourswrk;
double payrate;
double grosspay;
int empno;
char empname[20];
double netpay;
double tax = 0.25;
double taxdeduct;
double overt = 1.5;
double overtime;
for(int i = 0; i < 5; i++)
{
EmpData[i].getdetails();
EmpData[i].calculatepay();
EmpData[i].showdetails();
}
system("pause");
return 0;
}
i just added a global variable which has totgrosspay every time you enter grosspay grosspay is added to totgrosspay
#include<iostream>
long totgrosspay=0;
using namespace std;
class Employee {
private:
long grosspay=0;
double hourswrk;
double payrate;
int empno;
char empname[20];
double netpay;
double tax;
double overt;
double overtime;
double taxdeduct;
public:
void getdetails();
void calculatepay();
void showdetails();
};
void Employee::getdetails()
{
cout << "\nEnter employee name:\n";
cin >> empname;
cout << "\nEnter employee number:\n";
cin >> empno;
cout << "Enter hours worked:";
cin >> hourswrk;
cout << "Enter rate of pay";
cin >> payrate;
}
void Employee::calculatepay()
{
tax = 0.25;
overt = 1.5;
if(hourswrk >= 60)
{
grosspay = 0;
netpay = 0;
taxdeduct = 0;
cout << "You have exceeded the amount of hours!";
}
else if(hourswrk <= 40)
{
grosspay = hourswrk * payrate;
}
else if(hourswrk > 40 && hourswrk < 60)
{
overtime = hourswrk - 40;
grosspay = overt * payrate*overtime + hourswrk * payrate;
}
taxdeduct = tax * grosspay;
netpay = grosspay - taxdeduct;
totgrosspay= totgrosspay+grosspay;
}
void Employee::showdetails()
{
cout << "Employee Payslip\n";
cout << "Name: " << empname;
cout << "Employee number:" << empno;
cout << "Basic Salary" << payrate;
cout << "Hours work" << hourswrk;
cout << "Grosspay" << grosspay;
cout << "Tax: " << taxdeduct;
cout << "Net Salary" << netpay;
cout << endl;
}
int main()
{
Employee EmpData[5];
int i;
for(int i = 0; i < 5; i++)
{
EmpData[i].getdetails();
EmpData[i].calculatepay();
EmpData[i].showdetails();
}
cout<<totgrosspay;// it prints gross pay value
system("pause");
return 0;
}

Calculations no processing C++

I'm making a simple payroll calculator and for some reason my "taxes" aren't calculating. When I run the program they just show $0 in the output. Any idea whats causing this? I commented "// Not calculating. Shows $0" on the lines that aren't calculating.
#include <iostream>
using namespace std;
int main()
// Parameters: None
// Returns: Zero
// Calls: None
{
int const hourly_wage = 16.78, overtime_rate = 25.17, social_security = 0.06, federal_income = 0.14, state_income = 0.05, union_dues = 10;
int gross_pay, hours_worked, number_of_dependents, ss_withheld, federal_withheld, state_withheld, net_pay, insurance, overtime_pay, again;
cout << "This program will calculate payroll for an employee." << endl;
do
{
cout << "\n\nEnter the number of hours the employee worked: " << endl;
cin >> hours_worked;
if (hours_worked > 40) {
overtime_pay = (hours_worked - 40) * overtime_rate;
gross_pay = (40 * hourly_wage) + overtime_pay;
}
else {
gross_pay = hours_worked * hourly_wage;
}
cout << "\n\nEnter the number of dependents for employee: " << endl;
cin >> number_of_dependents;
if (number_of_dependents >= 3) {
insurance = 35;
}
else {
insurance = 0;
}
// Payroll Calculation
ss_withheld = gross_pay * social_security;
federal_withheld = gross_pay * federal_income;
state_withheld = gross_pay * state_income;
net_pay = gross_pay - (ss_withheld + federal_withheld + state_withheld + insurance + union_dues);
cout << "\n\nGross Pay: $" << gross_pay << endl;
cout << "Social Security Withhholding: $" << ss_withheld << endl; // Not calculating. Shows $0
cout << "Federal Withholding: $" << federal_withheld << endl; // Not calculating. Shows $0
cout << "State Withholding: $" << state_withheld << endl; // Not calculating. Shows $0
cout << "Union Dues: $" << union_dues << endl;
cout << "Insurance Deduction: $" << insurance << endl;
cout << "Net Pay: $" << net_pay << endl;
cout << "\nDo you want to do another employee(Y/N)? ";
cin >> again;
} while (again == 'y' || again == 'Y');
cout << "\nHope they enjoy the money!" << endl;
return 0;
}
It looks like you are creating int Const for double values. ie.
#include "stdafx.h";
#include <iostream>
using namespace std;
int main()
// Parameters: None
// Returns: Zero
// Calls: None
{
int const union_dues = 10;
double const hourly_wage = 16.78, overtime_rate = 25.17, social_security = 0.06, federal_income = 0.14, state_income = 0.05;
double gross_pay, hours_worked, number_of_dependents, ss_withheld, federal_withheld, state_withheld, net_pay, insurance, overtime_pay, again;
cout << "This program will calculate payroll for an employee." << endl;
do {
cout << "\n\nEnter the number of hours the employee worked: " << endl;
cin >> hours_worked;
if (hours_worked > 40) {
overtime_pay = (hours_worked - 40) * overtime_rate;
gross_pay = (40 * hourly_wage) + overtime_pay;
}
else {
gross_pay = hours_worked * hourly_wage;
}
cout << "\n\nEnter the number of dependents for employee: " << endl;
cin >> number_of_dependents;
if (number_of_dependents >= 3) {
insurance = 35;
}
else {
insurance = 0;
}
// Payroll Calculation
ss_withheld = gross_pay * social_security;
federal_withheld = gross_pay * federal_income;
state_withheld = gross_pay * state_income;
net_pay = gross_pay - (ss_withheld + federal_withheld + state_withheld + insurance + union_dues);
cout << "\n\nGross Pay: $" << gross_pay << endl;
cout << "Social Security Withhholding: $" << ss_withheld << endl; // Not calculating. Shows $0
cout << "Federal Withholding: $" << federal_withheld << endl; // Not calculating. Shows $0
cout << "State Withholding: $" << state_withheld << endl; // Not calculating. Shows $0
cout << "Union Dues: $" << union_dues << endl;
cout << "Insurance Deduction: $" << insurance << endl;
cout << "Net Pay: $" << net_pay << endl;
cout << "\nDo you want to do another employee(Y/N)? ";
cin >> again;
} while (again == 'y' || again == 'Y');
cout << "\nHope they enjoy the money!" << endl;
return 0;
}

Issues with int main()/functions

Hi my assignment is due in a couple of hours and I am trying to write my code to produce this output but it is not working. My program doesn't even run at all and always fails and I don't know what the issue is. I'm having issues with what to place in int main() and how to process the data from file to the functions! I have been trying forever.. In need of major help !!!!! thanks for your time
sample input file :
Miss Informed
125432 32560.0
Sweet Tooth
5432 9500
Bad Data
1255 -4500.0
John Smith
1225 3500.0
Nancy Brown
1555 154500.0
CODE:
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main()
{
float CalcIncomeTax(float );
float CalcNetSalary(float, float );
bool OpenFile(ifstream& fin);
bool OpenFile(ofstream& fout);
void Instruct(void);
void ReadData(ifstream & fin, string& Name , int &Id, float& grossIncome);
void Print(ofstream&, string, int, float, float, float);
ifstream fin;
ofstream fout;
string Name;
int Id = 0;
float grossIncome = 0;
float netSalary;
float incomeTax = 0;
Instruct ();
netSalary = CalcNetSalary(grossIncome,incomeTax);
incomeTax = CalcIncomeTax(grossIncome);
Print(fout, Name, Id, grossIncome, incomeTax, netSalary);
ReadData(fin, Name, Id, grossIncome);
OpenFile(fin);
{
getline(fin, Name);
while (!fin.eof())
{
fin >> Id >> grossIncome;
cout << setw(20) << left << Name
<< setw(8) << right << Id
<< setw(10) << grossIncome << endl;
fin.ignore(10,'\n');
fin >> Id >> grossIncome;
}
getline(fin,Name);
}
OpenFile(fout);
ReadData(fin, Name, Id, grossIncome);
fin.close();
}
bool OpenFile(ifstream&fin)
{
cout <<"\nEnter the name and location of the input file: ";
string file_input;
getline(cin, file_input);
fin.open(file_input.c_str() ) ;
if(fin.fail())
return false;
else
return true;
}
bool OpenFile(ofstream &fout)
{
cout <<"Enter the name and location of the output file: ";
string file_output;
getline(cin, file_output);
fout.open( file_output.c_str() );
if (fout.fail())
return false;
else
return true;
}
void Instruct()
{
cout << "Programmer:"<< setw(25) << "//" << endl;
cout << "Programming Assignment" << setw(5) << "4" << endl;
cout << "This program will calculate and report tax liability" << endl;
}
float CalcIncomeTax(float grossIncome)
{
float incomeTax = 0;
if (grossIncome <= 3500)
{
incomeTax = 0.00;
}
else if (grossIncome >= 3500 && grossIncome <= 8000)
{
incomeTax = 0 + 0.06 * (grossIncome - 3500);
}
else if (grossIncome >= 8000 && grossIncome <= 20000)
{
incomeTax = 270.00 + 0.11 * (grossIncome - 8000);
}
else if (grossIncome >= 20000 && grossIncome <= 34000)
{
incomeTax = 1590.00 + 0.17 * (grossIncome - 20000);
}
else if (grossIncome >= 34000 && grossIncome <= 54000)
{
incomeTax = 3970.00 + 0.24 * ( grossIncome - 34000);
}
else if (grossIncome >= 54000)
{
incomeTax = 8770.00 + 0.32 * ( grossIncome - 52000);
}
else if (grossIncome < 0)
{
cout << "****Invalid Income";
}
return(incomeTax);
}
float CalcNetSalary( float grossIncome, float incomeTax)
{
float netSalary;
netSalary = grossIncome - incomeTax;
return (netSalary);
}
void Print(ofstream& fout, string Name, int Id, float grossIncome, float incomeTax, float netSalary)
{
cout << setfill(' ') << left << setw(18) << "\tName";
cout << setfill(' ') << left << setw(12) << "ID";
cout << setfill(' ') << left << setw(17) << "Gross Income";
cout << setfill(' ') << left << setw(12) << "Taxes";
cout << setfill(' ') << left << setw(16) << "Net Income";
cout << endl;
cout << setfill('=') << setw(70)<<"\t";
cout<<endl;
cout << setprecision(2) << showpoint << fixed;
cout << setfill(' ') << "\t" << setw(17)<< Name;
cout << setfill(' ') << setw(12) << Id;
cout << '$' << setfill(' ') << setw(16) << grossIncome;
cout << '$' << setfill(' ') << setw(11) << incomeTax;
cout << '$' << setfill(' ') << setw(16) << netSalary;
cout << endl;
}
HOW OUTPUT SHOULD BE
Name ID Gross Income Taxes Net Income
Miss Informed 125432 $32560.00 **** Invalid ID
Sweet Tooth 5432 $9500.00 $435.00 $9065.00
Bad Data 1255 $-4500.00 **** Invalid Income
John Smith 1225 $3500.00 $0.00 $3500.00
Nancy Brown 1555 $154500.00 $40930.00 $113570.00
The way to write a program is not to write everything and then try to run it. Start small and simple, add complexity a little at a time, test at every step and never add to code that doesn't work.
This will take a few iterations. We'll start with something that can read from a file:
#include <iostream>
#include <fstream>
#include <string>
using namespace std; // This is a good TEMPORARY SHORTCUT.
int main()
{
ifstream fin("inputdata");
string firstName, lastName;
fin >> firstName >> lastName;
cout << "First name is " << firstName << endl;
cout << "Last name is " << lastName << endl;
return(0);
}
Post a comment when you have this working, and we'll go the next step.

Having a hard time my code

I am taking a C++ class and I have to build a payroll system. I am having a hard time trying to figure out what is wrong with my code. I can get the employees hours to produce but I have an new issue with my code now. I thought it was correct, but guess not. Now the new problem is that I can get the employees hours to produce but when I do my code wants to multiple my overtime hours times 3 and produce an output of the person who has the overtime hours twice.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//
//CLASS DECLARATION SECTION
//
class EmployeeClass {
public:
void ImplementCalculations(string EmployeeName, int hours, float wage);
void DisplayEmployInformation(void);
void Addsomethingup (EmployeeClass Emp1, EmployeeClass Emp2, EmployeeClass Emp3);
string EmployeeName;
int hours ;
float wage ;
float basepay ;
int overtime_hours ;
float overtime_pay ;
float overtime_extra ;
float iTotal_salaries ;
float iIndividualSalary ;
int iTotal_hours ;
int iTotal_OvertimeHours ;
};
int main()
{ system("cls");
cout << "\nWelcome to Data Max Inc. Employee Pay Center\n\n" ;
EmployeeClass Emp1;
EmployeeClass Emp2;
EmployeeClass Emp3;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "\n\nEnter the first employee's first name = ";
cin >> Emp1.EmployeeName;
cout << "\n\nEnter the hours worked = ";
cin >> Emp1.hours;
cout << "\n\nEnter employee's hourly wage = ";
cin >> Emp1.wage;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "\n\nEnter the second employee's first name = ";
cin >> Emp2.EmployeeName;
cout << "\n\nEnter the hours worked = ";
cin >> Emp2.hours;
cout << "\n\nEnter employee's hourly wage = ";
cin >> Emp2.wage;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "\n\nEnter the third employee's first name = ";
cin >> Emp3.EmployeeName;
cout << "\n\nEnter the hours worked = ";
cin >> Emp3.hours;
cout << "\n\nEnter employee's hourly wage = ";
cin >> Emp3.wage;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << endl;
Emp1.ImplementCalculations(Emp1.EmployeeName, Emp1.hours, Emp1.wage);
Emp2.ImplementCalculations(Emp2.EmployeeName, Emp2.hours, Emp2.wage);
Emp3.ImplementCalculations(Emp3.EmployeeName, Emp3.hours, Emp3.wage);
cin.get();
return 0;
} //End of Main Function
void EmployeeClass::ImplementCalculations (string employeeFirstName, int hours, float wage){
//Initialize overtime variables
overtime_hours=0;
overtime_pay=0;
overtime_extra=0;
if (hours > 40)
{
basepay = 40 * wage;
overtime_hours = hours - 40;
overtime_pay = wage * 1.5;
overtime_extra = overtime_hours * overtime_pay;
iIndividualSalary = overtime_extra + basepay;
DisplayEmployInformation();
} // if (hours > 40)
else
{
basepay = hours * wage;
iIndividualSalary = basepay;
} // End of the else
DisplayEmployInformation();
} //End of Primary Function
void EmployeeClass::DisplayEmployInformation () {
// This function displays all the employee output information.
cout << "\n\n";
cout << "Employee First Name ............. = " << EmployeeName << endl;
cout << "Base Pay ........................ = " << basepay << endl;
cout << "Hours in Overtime ............... = " << overtime_hours << endl;
cout << "Overtime Pay Amout............... = " << overtime_extra << endl;
cout << "Total Pay ....................... = " << iIndividualSalary << endl;
} // END OF Display Employee Information
void EmployeeClass::Addsomethingup (EmployeeClass Emp1, EmployeeClass Emp2, EmployeeClass Emp3){
iTotal_salaries = 0;
iTotal_hours = 0;
iTotal_OvertimeHours = 0;
iTotal_hours = Emp1.hours + Emp2.hours + Emp3.hours;
iTotal_salaries = iIndividualSalary + iIndividualSalary + iIndividualSalary;
iTotal_OvertimeHours = overtime_hours + overtime_hours + overtime_hours;
cout << "\n\n";
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%% Total Employee Salaries ..... = " << iTotal_salaries << endl;
cout << "%%%% Total Employee Hours ........ = " << iTotal_hours << endl;
cout << "%%%% Total Overtime Hours......... = " << iTotal_OvertimeHours << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
} // End of function
You aren't calling Addsomethingup anywhere. You probably also want this to be a static method. If you haven't learned what those are yet, don't worry.
At the end of your main function, but before cin.get(), try adding:
Emp1.Addsomethingup(Emp1, Emp2, Emp3);

How do I enter a loop in another loop?

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int employeeNum = 0; int totalEmployees = 0;
double hourlyRate = 0.0; double totalhoursWork = 0.0;
double hoursWork = 0.0; double totalnetPay = 0.0;
double grossPay = 0.0; double averagehoursWork = 0.0;
double netPay = 0.0; double totalwithHoldings = 0.0;
double withHoldings = 0.0; double overTime = 0.0;
int x = 0;
while(employeeNum!= 9999)
{
cout <<" Enter Employee Number (9999 to Stop):";
cin >> employeeNum;
if(employeeNum ==9999)
break;
cout <<"Enter hourly rate:";
cin >> hourlyRate;
cout <<"Enter hours worked:";
cin >> hoursWork;
cout <<"Employee Number:"<<employeeNum << endl;
if(hoursWork <= 40)
{
grossPay= hoursWork * hourlyRate;
cout <<" Gross Weekly Pay=" << fixed <<setprecision(2)<< grossPay << endl;
}
else if (hoursWork > 40)
{
overTime = hoursWork-40;
grossPay = (overTime * 1.5 + 40)* hourlyRate;
cout <<" Gross Weekly Pay="<< fixed <<setprecision(2)grossPay << endl;
}
if( grossPay > 1000.00)
{
withHoldings= grossPay*0.28;
}
else if( grossPay <= 1000.00)
{
withHoldings= grossPay*0.21;
}
netPay= grossPay-withHoldings;
cout <<" Net Weekly Pay="<<fixed << setprecision(2) << netPay << endl;
totalhoursWork+=hoursWork;
totalnetPay+=netPay;
totalwithHoldings+= withHoldings;
averagehoursWork= totalhoursWork/totalEmployees;
totalEmployees++;
}
averagehoursWork= totalhoursWork/totalEmployees;
for (int x = 1; x < 44; x = x + 1)
cout <<"*";
cout << endl;
cout <<"Total Employees Entered=" << totalEmployees << endl;
cout <<" Total Hours Worked="<< fixed << setprecision(2) << totalhoursWork << endl;
cout <<" Average Hours Worked="<< fixed << setprecision(2) << averagehoursWork << endl;
cout <<" Total Net Pay="<<fixed << setprecision(2) << totalnetPay << endl;
cout <<" TotalwithHoldings=" << fixed << setprecision(2)<< totalwithHoldings << endl;
for (int x = 1; x < 44; x = x + 1)
cout <<"*";
cout << endl;
system("pause");
return 0;
}
Hourly rate must be greater than $7.25 and less than $100.00. Hours worked must be greater than 0 and less than 120. If the user enters invalid data display and appropriate error message and ask the user to re-enter. What statement should I use for this portion and where should I put it??
You can use Cin and Cout for Input and output,, just use do While loop
int employeeNum = 0;
do
{
Console.WriteLine("enter Employee /Number 9999 to STOP");
employeeNum = int.Parse(Console.ReadLine());
if (employeeNum == 9999)
break;
Console.WriteLine("enter hourly rate ");
double hourRate = Double.Parse(Console.ReadLine());
} while (employeeNum != 9999);
You can do something like this:
cout << "Enter hourly rate:";
cin >> hourlyRate;
while (hourlyRate <= 7.25 || hourlyRate >= 100) {
cout << endl << "Reenter hourly rate (must be in (7.25 - 100))";
cin >> hourlyRate;
}
But stackoverflow is not for others do you'r homework.