d2jsp
d2jsp Forums > Programmer's Haven > C/C++/C# > Debug Simple Program For 150fg > Details Inside
Add Reply New Topic New Poll
flowrevolution
#1 Oct 23 2017 03:39pm
Group: Member
Posts: 5,509
Joined: May 6 2008
Gold: 3,917.00
// payroll.cpp

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;



int main()

{
int EmployeeType{ 0 };
double HourlyRate{ 0 };
double AnnualSalary{ 0 };
double HoursWorked{ 0 };
double Pay{ 0 };

do {
cout << "Enter Employee type/nHourly Employee: 1/n Salary Employee: 2/n Exit program: -1";
while (!(cin >> EmployeeType))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please Re-Enter ( Entry Invalid )" << endl;
cout << "Enter Employee type: ";
}


if (EmployeeType != -1)

{
switch (EmployeeType)


{
case 1:
{ cout << "Enter Employee's Hourly rate: ";
while (!(cin >> HourlyRate))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please Re-Enter ( Entry Invalid )" << endl;
cout << "Enter Employee's Hourly rate:";
}


cout << "Enter Employee's Hours Worked: ";
while (!(cin >> HoursWorked))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please Re-Enter ( Entry Invalid )" << endl;
cout << "Enter Employee's Hours Worked: ";
}
}
Pay = HourlyRate*HoursWorked;
cout << fixed << setprecision(2);
cout << "Payment: $" << Pay << endl;

if (!cin)
{
break;
}
else
{
break;
}

return 0;
case 2:
{ cout << "Enter Employee's Annual Salary: ";
while (!(cin >> AnnualSalary))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please Re-Enter ( Entry Invalid )" << endl;
cout << "Enter Employee's Annual Salary: ";
}
Pay = AnnualSalary / 52;
cout << fixed << setprecision(2);
cout << "Payment: $" << Pay << endl;


if (!cin)
{
break;
}
else
{
break;
}
}
return 0;
}
}
}



Severity Code Description Project File Line Suppression State
Error C1075 the left brace '{' was unmatched at the end of the file Project1 c:\users\funnyhorse\documents\payroll.cpp 12
Severity Code Description Project File Line Suppression State
Error (active) E0112 expected 'while' Project1 c:\Users\Funnyhorse\Documents\payroll.cpp 97


let me know if you need more info or this doesn't make sense

This post was edited by flowrevolution on Oct 23 2017 03:40pm
waraholic
#2 Oct 23 2017 04:26pm
Group: Member
Posts: 1,007
Joined: Jul 8 2008
Gold: 2,109.50
your first do/while was wonky so I fixed it. The program isn't complete, but it compiles and takes your first number selection properly

Code

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()

{
int EmployeeType{0};
double HourlyRate{0};
double AnnualSalary{0};
double HoursWorked{0};
double Pay{0};

do
{
cout << "Enter Employee type.\nHourly Employee: 1\nSalary Employee: 2\nExit program: -1\n";
cin >> EmployeeType;
if (EmployeeType != -1 && EmployeeType != 1 && EmployeeType != 2) {
cout << "Invalid Selection";
} else {
break;
}
} while ( true );

{
cin.clear();
//cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please Re-Enter ( Entry Invalid )" << endl;
cout << "Enter Employee type: ";
}

if (EmployeeType != -1)

{
switch (EmployeeType)

{
case 1:
{
cout << "Enter Employee's Hourly rate: ";
while (!(cin >> HourlyRate))
{
cin.clear();
//cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please Re-Enter ( Entry Invalid )" << endl;
cout << "Enter Employee's Hourly rate:";
}

cout << "Enter Employee's Hours Worked: ";
while (!(cin >> HoursWorked))
{
cin.clear();
//cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please Re-Enter ( Entry Invalid )" << endl;
cout << "Enter Employee's Hours Worked: ";
}
}
Pay = HourlyRate * HoursWorked;
cout << fixed << setprecision(2);
cout << "Payment: $" << Pay << endl;

if (!cin)
{
break;
}
else
{
break;
}

return 0;
case 2:
{
cout << "Enter Employee's Annual Salary: ";
while (!(cin >> AnnualSalary))
{
cin.clear();
// cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Please Re-Enter ( Entry Invalid )" << endl;
cout << "Enter Employee's Annual Salary: ";
}
Pay = AnnualSalary / 52;
cout << fixed << setprecision(2);
cout << "Payment: $" << Pay << endl;

if (!cin)
{
break;
}
else
{
break;
}
}
return 0;
}
}
}
Go Back To C/C++/C# Topic List
Add Reply New Topic New Poll