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;
}
Related
#include <iostream>
#include <string>
using namespace std;
void calculateCarpetSize (int length, int width)
{
float carpetSize = (length * width);
cout.setf(ios::fixed);
cout.precision(0);
}
void calculateCarpetPrice (float carpetSize, float sellingPrice )
{
float carpetPrice = ( carpetSize * sellingPrice );
}
void calculateCarpetCost (float carpetSize, float sellingPrice )
{
float salesTax = 0.14;
float carpetCost = (carpetSize * sellingPrice * salesTax);
cout.precision(2);
}
void calculateLabourCost ( float carpetSize, float labour)
{
labour = 24.00;
float labourCost = carpetSize * labour;
}
bool qualifyForDiscount (int customerNumber)
{
if ( customerNumber < 99999)
{
void computeDiscount (float carpetCost);
return true;
}
else
{
return false;
}
}
void computeDiscount (float carpetCost, float discountPercentage)
{
cout << "Enter the percentage discount ." << endl;
cin >> discountPercentage;
float carpetCostDiscount = carpetCost * discountPercentage;
}
void printCustomerStatement( )
{
cout.setf(ios::fixed);
cout << endl;
cout << "CROSWELL CARPET STORE" << endl;
cout << "STATEMENT" << endl;
}
int main()
{
int customerName;
int customerSurname;
int customerNumber;
float carpetSize;
float carpetPrice;
float sellingPrice;
float salesTax = 0.14;
float labourCost;
int labour = 24.00;
float length;
float width;
float discount;
float discountPercentage;
cout.setf(ios::fixed);
cout.precision(2);
cout << "Please enter the information" << endl;
cout << "Enter the customer's first name: " << endl;
cin >> customerName;
cout << "\n Enter customers surname: " << endl;
cin >> customerSurname;
cout << "\n The length of the room: " << endl;
cin >> length;
cout << "\n Enter the width of the room: " << endl;
cin >> width;
cout << "\n Enter the carpet selling price: " << endl;
cin >> sellingPrice;
int printCustomerStatement;
{
cout << "\n Customer name : " << endl;
cin >> customerName >> customerSurname ;
cout << "Customer number : " << endl;
cin >> customerNumber;
cout << "\n Carpet price : " << endl;
cin >> carpetPrice;
cout << "Labour : " << endl;
cin >> labour;
cout << "\n Subtotal : " << endl;
cin >> carpetPrice;
cout << "Less Discount : " << endl;
cin >> qualifyForDiscount;
cout << "\n Subtotal: " <<endl;
cin >> carpetPrice;
cout << "Plus tax: " << endl;
cin >> salesTax;
cout << "Total: " << endl;
cin >> carpetPrice;
}
return 0;
}
There is an error and I cant figure out how to solve it.
error: ambiguous overload for 'operator>>' in 'std::cin >> qualifyForDiscount'
Please help me out.
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
Hello i am working on a program to store a users input of prices into an array. then have a module accept the price array and return tax. here is what i have so far. my module keeps producing LNK2019.
#include <iostream>
using namespace std;
double PrArray[20] = {}, total_price, tax_rate, price, tax;
int i;
double TAXOWED();
void main()
{
cout << "input the sales tax rate as a decimal ";
cin >> tax_rate;
cout << "\nplease enter a price or 0 to quit ";
i = 0;
cin >> price;
PrArray[i] = price;
while (price > 0 && i < 19)
{
i++;
cout << "please enter a price or 0 to quit ";
cin >> price;
PrArray[i] = price;
}
for (i = 0; i < 19; i++)
{
cout << "\n";
cout << PrArray[i];
}
TAXOWED();
system("PAUSE");
return;
}
double TAXOWED(double PrArray[], int i)
{
double total_tax;
for (i = 0; i < 19; i++)
{
tax = tax_rate * PrArray[i];
total_tax = tax;
}
return(total_tax);
}
Your function declaration and definition don't match
// Declaration
double TAXOWED();
// Definition
double TAXOWED(double PrArray[], int i);
So essentially your are declaring a function and never defining it, then defining a separate function below.
Relaying on your comment, the code should looks like this:
#include <iostream>
using namespace std;
double TAXOWED(double price, double tax_rate)
{
return tax_rate * price;
}
int main()
{
double PrArray[20], total_tax[20], tax_rate, price;
cout << "input the sales tax rate as a decimal ";
cin >> tax_rate;
cout << "\nplease enter a price or 0 to quit ";
cin >> price;
if ( price == 0 )
return -1;
int i = 0;
PrArray[i] = price;
for (i = 1; i < 20; i++)
{
cout << "please enter a price or 0 to quit " ;
cin >> price;
PrArray[i] = price;
}
for (int i = 0 ; i < 20; i++)
total_tax[i] = TAXOWED(PrArray[i], tax_rate);
for (int i = 0; i < 20; i++)
cout << "Tax for price #" << i << " : " << total_tax[i] << endl;
system("PAUSE");
return 0;
}
This code will allow you to set tax_rate, each price value and output tax_rate for each price.
Ok this is what i have now. i need the chart at the end to have all the total prices added together
#include <iostream>
using namespace std;
// declerations
double PrArray[20], total_tax[20], tax_rate, price, total_price;
int i;
double TAXOWED(double price, double tax_rate)
{
return tax_rate * price;
}
void main()
{
cout << "input the sales tax rate as a decimal ";
cin >> tax_rate;
cout << "\nplease enter a price or 0 to quit ";
i = 0;
cin >> price;
PrArray[i] = price;
while (price > 0 && i < 19)
{
i++;
cout << "please enter a price or 0 to quit ";
cin >> price;
PrArray[i] = price;
}
for (int i = 0; i < 20; i++)
{
total_tax[i] = TAXOWED(PrArray[i], tax_rate);
}
system("CLS");
cout << " Prices";
cout << "\ntaxrate % " << tax_rate;
cout << "\nprices tax Total price ";
cout << "\n__________________________________________________";
for (int i = 0; i < 20; i++)
{
cout << "\n" << PrArray[i] << " " << total_tax[i] << " " << PrArray[i] + total_tax[i];
}
for (int)
system("PAUSE");
return;
}
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);
#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.