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);
Related
I have already checked all the other questions but I just can't fix it.. I am a nuub at coding.
I don't know why it says it needs a while or where to put it, and it gives the wrong answer for the LOCS function also is there anything i can do about the default pointer warning. this is just a start i will be extending this later so it would be a big help and i have tried while and closing brackets everywhere lol
Btw if anyone can tell me how I can use the input as decision as you can see I am using 1 and 2, but If I could use permanent and casual that would be great.
// Calculate an employee's weekly salary
// Use a do while loop, and an if else statement to have user input data and display the correct values
#include <iostream>
using namespace std;
void main()
{
//Declaring the constant variables
const double BONUS_RATE = 5.0;
//Declaring the variables
int hours;
int sales;
int Status;
string permanent, casual, Name, status, result, employee;
double rate, sale_bonus, netPay, gross;
//set decimal point to 2 positions
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
//Display name
cout << "Calculate an employee's weekly salary\n\n";
//Do while loop to get hourly rate
do {
cout << "Enter employee name: ";
cin >> Name;
cout << "Please enter 1 if employee is permanent or 2 if casual: ";
cin >> Status;
Status = 0;
while (Status < 1 || Status > 2);
if (Status = 1)
{
cout << "Permanent employees have a fixed salary of $1000 per week" << endl;
sales = 0;
(sales < 1 || sales > 10);
cout << "If any please enter how many sales employee made this week:";
cin >> sales;
sale_bonus = sales * BONUS_RATE;
netPay = 1000 + sale_bonus;
cout << endl;
cout
<< "Hours Worked: \t" << hours << endl
<< "Gross Pay: \t" << gross << endl
<< "Net Pay \t" << netPay << endl;
}
else if (Status = 2) {
cout << "Casual employee's hourly rate is $15";
rate = 15.00;
cout << endl;
//while loop for hours
hours = 0;
while (hours < 1 || hours > 60)
{
cout << "Please enter how many hours you have worked this week:" << endl;
cout << "Minimum hours is 1" << endl;
cout << "Maximum hours are 60" << endl;
cout << "Enter hours worked: ";
cin >> hours;
}
//while loop for bonus
sales = 0;
while (sales < 1 || sales > 10)
{
cout << "Please enter how many sales you made this week:";
cin >> sales;
}
//Calculate pay
gross = hours * rate;
sale_bonus = sales * BONUS_RATE;
netPay = gross + sale_bonus;
//Display the results
cout << endl
<< "Hourly Rate: \t" << rate << endl
<< "Hours Worked: \t" << hours << endl
<< "Gross Pay: \t" << gross << endl
<< "Net Pay \t" << netPay << endl;
}
}
}
#include <iostream>
using namespace std;
void main()
{
//Declaring the constant variables
const double BONUS_RATE = 5.0;
//Declaring the variables
int hours;
int sales;
int Status;
string permanent, casual, Name, status, result, employee;
double rate, sale_bonus, netPay, gross;
//set decimal point to 2 positions
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
//Display name
cout << "Calculate an employee's weekly salary\n\n";
//Do while loop to get hourly rate
do {
cout << "Enter employee name: ";
cin >> Name;
cout << "Please enter 1 if employee is permanent or 2 if casual: ";
cin >> Status;
} while (Status < 1 || Status > 2); // add while after do block with }
if (Status == 1)// use '==' equality check not '=' .
{
cout << "Permanent employees have a fixed salary of $1000 per week" << endl;
sales = 0;
(sales < 1 || sales > 10);
cout << "If any please enter how many sales employee made this week:";
cin >> sales;
sale_bonus = sales * BONUS_RATE;
netPay = 1000 + sale_bonus;
cout << endl;
cout
<< "Hours Worked: \t" << hours << endl
<< "Gross Pay: \t" << gross << endl
<< "Net Pay \t" << netPay << endl;
}
else if (Status == 2) { // use '==' equality check not '=' .
cout << "Casual employee's hourly rate is $15";
rate = 15.00;
cout << endl;
//while loop for hours
hours = 0;
while (hours < 1 || hours > 60)
{
cout << "Please enter how many hours you have worked this week:" << endl;
cout << "Minimum hours is 1" << endl;
cout << "Maximum hours are 60" << endl;
cout << "Enter hours worked: ";
cin >> hours;
}
//while loop for bonus
sales = 0;
while (sales < 1 || sales > 10)
{
cout << "Please enter how many sales you made this week:";
cin >> sales;
}
//Calculate pay
gross = hours * rate;
sale_bonus = sales * BONUS_RATE;
netPay = gross + sale_bonus;
//Display the results
cout << endl
<< "Hourly Rate: \t" << rate << endl
<< "Hours Worked: \t" << hours << endl
<< "Gross Pay: \t" << gross << endl
<< "Net Pay \t" << netPay << endl;
}
}
I have made the suitable changes :
Use == to check equality instead of = operator!
Syntax of do while : do { //code... } while(condition).
The while must follow the do after closing the block!
Your Mistake
the main mistake is you have not close the do while loop, ask in comment for more clarification!
PS. I recommend you first copy my code and then run, and then analyse the issue!
Use this code this will work
#include
using namespace std;
void main()
{
//Declaring the constant variables
const double BONUS_RATE = 5.0;
//Declaring the variables
int hours;
int sales;
int Status;
string permanent, casual, Name, status, result, employee;
double rate, sale_bonus, netPay, gross;
//set decimal point to 2 positions
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
//Display name
cout << "Calculate an employee's weekly salary\n\n";
//Do while loop to get hourly rate
while(1){
cout << "Enter employee name: ";
cin >> Name;
cout << "Please enter 1 if employee is permanent or 2 if casual: ";
cin >> Status;
Status = 0;
while (Status < 1 || Status > 2);
if (Status = 1)
{
cout << "Permanent employees have a fixed salary of $1000 per week" << endl;
sales = 0;
(sales < 1 || sales > 10);
cout << "If any please enter how many sales employee made this week:";
cin >> sales;
sale_bonus = sales * BONUS_RATE;
netPay = 1000 + sale_bonus;
cout << endl;
cout
<< "Hours Worked: \t" << hours << endl
<< "Gross Pay: \t" << gross << endl
<< "Net Pay \t" << netPay << endl;
}
else if (Status = 2) {
cout << "Casual employee's hourly rate is $15";
rate = 15.00;
cout << endl;
//while loop for hours
hours = 0;
while (hours < 1 || hours > 60)
{
cout << "Please enter how many hours you have worked this week:" << endl;
cout << "Minimum hours is 1" << endl;
cout << "Maximum hours are 60" << endl;
cout << "Enter hours worked: ";
cin >> hours;
}
//while loop for bonus
sales = 0;
while (sales < 1 || sales > 10)
{
cout << "Please enter how many sales you made this week:";
cin >> sales;
}
//Calculate pay
gross = hours * rate;
sale_bonus = sales * BONUS_RATE;
netPay = gross + sale_bonus;
//Display the results
cout << endl
<< "Hourly Rate: \t" << rate << endl
<< "Hours Worked: \t" << hours << endl
<< "Gross Pay: \t" << gross << endl
<< "Net Pay \t" << netPay << endl;
}
}
}
My code compiles nicely, but the math formulas that I am using aren't providing the right outcome. I need to calculate the balance, withdrawn, and interest for all 3 months. I am also required to validate user's input. For these purposes I am using nested loops. Please let me know if you spot my mistake. Thank you lovely people!
cout << "Please enter the starting balance: ";
cin >> startBalance;
cout << "Please enter the annual interest rate: ";
cin >> annualInterest;
for (int month = 1; month <= 3; month++) {
do {
cout << setprecision(5);
cout << "Please enter the total amount deposited on month " << month << ": ";
cin >> balance;
if (balance <0) {
goodChoice = false;
cout << "\n\t***ERROR " << balance << " ***";
cout << "*** Choice must be positive***\n" << endl;
}
else {
goodChoice = true;
}
startBalance += balance; //need to calculate the balance for all 3 months
} while (!goodChoice);
do {
cout << setprecision(5);
cout << "Please enter the total amount withdrawn on " << month << ": ";
cin >> withdrawn;
if ( (withdrawn <0) || (withdrawn > startBalance) ) {
goodChoice = false;
cout << "***ERROR " << withdrawn << " ***";
cout << "*** Choice must be positive or greater than the balance***" << endl;
}
else {
goodChoice = true;
}
finalWithdrawn += withdrawn; // the total amount of withdrawn
finalBalance = startBalance - withdrawn;
monthInterest = ((startBalance + finalBalance) / 2) * (annualInterest / 12);
totalInterest += monthInterest; //total interest for all 3 months
endBalance = monthInterest + finalBalance;
} while (!goodChoice);
}
cout << "Total Deposit: " << endBalance << endl;
cout << "Total Withdrawn: " << finalWithdrawn << endl;
cout << "Total Interest: " << totalInterest << endl;
cout << "Final Balance: " << endBalance << endl;
You have a lot of extra variables defined which aren't needed. Also, your interest rate may have been in percentage instead of a decimal number, i.e. 10% = 0.1. Also, your monthInterest is taking an average then applying interest. I wrote this up and it seems to work.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float totalDeposit = 0.0f;
float totalWithdrawn = 0.0f;
float totalInterest = 0.0f;
float totalBalance = 0.0f;
float interestRate = 0.0f;
setprecision(5); //?
cout << "Enter starting balance: ";
cin >> totalBalance;
cout << "Enter annual interest rate (%): ";
cin >> interestRate;
// Convert to monthly and non-percent; i.e. 10% = 0.1 = 10 / 100
interestRate = interestRate / 100.0f / 12.0f;
for (int month = 1; month <= 3; month++)
{
float deposit = -1.0; // Default to an error state
while (deposit < 0.0)
{
cout << "Enter total deposited in month " << month << ": ";
cin >> deposit;
if (deposit < 0.0f)
{
cout << "ERROR: Invalid amount" << endl;
continue;
}
}
float withdrawn = -1.0f; // Default to an error state
while (withdrawn < 0.0f)
{
cout << "Enter total withdrawn in month " << month << ": ";
cin >> withdrawn;
if (withdrawn < 0.0f)
{
cout << "ERROR: Invalid amount" << endl;
continue;
}
}
totalDeposit += deposit;
totalWithdrawn += withdrawn;
totalBalance = totalBalance + deposit - withdrawn;
totalBalance += totalBalance * interestRate;
totalInterest += totalBalance * interestRate;
}
cout << "Total Deposit: " << totalDeposit << endl;
cout << "Total Withdrawn: " << totalWithdrawn << endl;
cout << "Total Interest: " << totalInterest << endl;
cout << "Final Balance: " << totalBalance << endl;
int wait; // Pause so console window doesn't close. Delete this line.
cin >> wait;
return 0;
}
Alright So I finished my program that is basically just calculating up hours worked for 3 employees, nothing too complicated. However, now that I am finished I get two error messages. The first says:
expression must be a modifiable lvalue.
This refers to the use of x.hours under the Addsomethingup function. The second error message says:
'=': left operand must be l-value.
This also says that it has something to do with that iTotal_hours line under the Addsomethingup function. I am not too familiar with Classes using C++ so if anyone can offer some advice I would really appreciate it.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class EmployeeClass {
public:
string EmployeeName;
int hours;
float wage;
float basepay;
float salary;
int overtime_hours;
float overtime_pay;
float overtime_extra;
float iTotal_salaries;
float iIndividualSalary;
int iTotal_hours;
int iTotal_OvertimeHours;
void ImplementCalculations() {
overtime_hours = 0;
overtime_pay = 0;
overtime_extra = 0;
if (hours > 40) {
overtime_hours = hours - 40;
}
else {
overtime_hours = 0;
}
basepay = 40 * wage;
overtime_pay = wage * 1.5;
overtime_extra = overtime_pay * overtime_hours;
salary = overtime_extra + basepay;
}
void DisplayEmployInformation(void) {
cout << "Employee Name ............. = " << EmployeeName << endl <<
"Base Pay .................. = " << basepay << endl <<
"Hours in Overtime ......... = " << overtime_hours << endl <<
"Overtime Pay Amount........ = " << overtime_pay << endl <<
"Total Pay ................. = " << salary << endl;
}
void Addsomethingup(EmployeeClass x, EmployeeClass y, EmployeeClass z) {
iTotal_salaries = 0;
iTotal_hours = 0;
iTotal_OvertimeHours = 0;
iTotal_salaries = x.wage + y.wage + z.wage;
iTotal_hours = x.hours + y.hours = z.hours;
iTotal_OvertimeHours = x.overtime_hours + y.overtime_hours + z.overtime_hours;
cout << " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" <<
"%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%\n" <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" <<
"%%%% Total Employee Salaries ..... = " << iTotal_salaries << endl <<
"%%%% Total Employee Hours ........ = " << iTotal_hours << endl <<
"%%%% Total Overtime Hours......... = " << iTotal_OvertimeHours << endl <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
}
};
int main()
{
system("cls");
cout << "\nWelcome to the Employee Pay Center\n\n";
EmployeeClass firstEmployee;
EmployeeClass secondEmployee;
EmployeeClass thirdEmployee;
EmployeeClass totalEmployee;
cout << "Please enter the first Employees name: \n"; //First employees input
cin >> firstEmployee.EmployeeName;
cout << "Please enter " << firstEmployee.EmployeeName << "'s hours worked: \n";
cin >> firstEmployee.hours;
cout << "Please enter " << firstEmployee.EmployeeName << "'s hourly wage; \n\n";
cin >> firstEmployee.wage;
cout << "Please enter the second Employees name: \n"; //Second emlpoyee input
cin >> secondEmployee.EmployeeName;
cout << "Please enter " << secondEmployee.EmployeeName << "'s hours worked: \n";
cin >> secondEmployee.hours;
cout << "Please enter " << secondEmployee.EmployeeName << "'s hourly wage; \n\n";
cin >> secondEmployee.wage;
cout << "Please enter the third Employees name: \n"; //Third employees input
cin >> thirdEmployee.EmployeeName;
cout << "Please enter " << thirdEmployee.EmployeeName << "'s hours worked: \n";
cin >> thirdEmployee.hours;
cout << "Please enter " << thirdEmployee.EmployeeName << "'s hourly wage; \n\n";
cin >> thirdEmployee.wage;
firstEmployee.ImplementCalculations();
secondEmployee.ImplementCalculations();
thirdEmployee.ImplementCalculations();
totalEmployee.Addsomethingup(firstEmployee, secondEmployee, thirdEmployee);
}
Your issue is with
iTotal_hours = x.hours + y.hours = z.hours;
operator precendece dictates that x.hours + y.hours happens before y.hours = z.hours so what is actually going on is
iTotal_hours = (x.hours + y.hours) = z.hours;
Which will not work as (x.hours + y.hours) creates a temporary object that cannot be assigned to.
I think what you meant to have was a + and not an = which would make it
iTotal_hours = x.hours + y.hours + z.hours;
which is consistent with what you did for iTotal_salaries and iTotal_OvertimeHours
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
I am getting an uninitialized Local variable error when I do believe I have already initialized. The error reads uninitialized local variable wk1 being used (It's wk1-wk5).
Here is the code:
#include <iostream>
using namespace std;
const double tax = 0.14;
int main()
{
int wk1,wk2,wk3,wk4,wk5;
wk1,wk2,wk3,wk4,wk5 = 0;
int thours = wk1 + wk2 + wk3 + wk4 + wk5; <------------ This is the error line.
thours = 0;
double payrate;
payrate = 0;
double gross = thours * payrate;
double taxes = tax * gross;
double net = gross - taxes;
double clothes = 0.10 * net;
double supplies = 0.10 * net;
double remaining = net - clothes - supplies;
double bonds = 0.25 * remaining;
double pbonds = 0.50 * bonds;
bonds = 0;
gross = 0;
net = 0;
clothes = 0;
supplies = 0;
remaining = 0;
cout << "Please enter the payrate for employee." << endl;
cin >> payrate;
payrate = 0;
cout << "Please enter employee's total hours for week one:" << endl;
cin >> wk1;
wk1 = 0;
cout << "Please enter employee's total hours for week two:" << endl;
cin >> wk2;
wk2 = 0;
cout << "Please enter employee's total hours for week three:" << endl;
cin >> wk3;
wk3 = 0;
cout << "Please enter employee's total hours for week four:" << endl;
cin >> wk4;
wk4 = 0;
cout << "Please enter employee's total hours for week five:" << endl;
cin >> wk5;
wk5 = 0;
cout << "Here is income before taxes: " << gross << endl;
cout << "Here is income after taxes: " << net << endl;
cout << "Here is clothes and accesories: " << clothes << endl;
cout << "Here is School supplies: " << supplies << endl;
cout << "Here is personal bonds: " << bonds << endl;
cout << "Here is parents bonds: " << pbonds << endl;
return 0;
}
wk1,wk2,wk3,wk4,wk5 = 0;
This line is a comma operator expression, which is equivalent to:
wk5 = 0;
Because expressions like wk1 has no side effect. Only the variable wk5 has been assigned a value, the other variables are still uninitialized. You can do:
wk1 = wk2 = wk3 = wk4 = wk5 = 0;