Apr 30, 2010 at 6:15pm UTC
I need to know how to call the displayOutput function into my main function in order to display the data.
#include<iostream>
#include<iomanip>
using namespace std;
//Function Prototypes
//Calculate Pay
int calcPay(int, char);
//Calculate Tax
int calcTax(double);
//Calculate Insurance
int calcInsurance(int, double);
//Display Input
int displayInput(int, int, int, char);
//Display Output
int displayOutput(double, double, double, double, double);
int main()
{
//Declare Variables
int employeeNumber = 0, hoursWorked = 0, insuranceType = 0;
char employeePosition;
double grossPay = 0, bonusPay = 0, totalPay = 0, insurance = 0, taxAmt = 0;
//Get employee number and verify whether or not they wish to continue
cout << "Enter your employee number (enter 0 to quit): ";
cin >> employeeNumber;
if(employeeNumber == 0)
{
system("pause");
return 0;
}
//Get hours worked
cout << "Enter your hours worked: ";
cin >> hoursWorked;
//Get employee position and employee insurance type and verify
cout << "Enter your position (e for employee, s for supervisor, m for manegment): ";
cin >> employeePosition;
if(employeePosition != 'e' && employeePosition != 's' && employeePosition != 'm')
{
cout << "Invalid position please enter e, s, or m." << endl;
}
else
{
cout << "Enter your insurance type (1-4): " << endl;
cin >> insuranceType;
if(insuranceType != 1 && insuranceType != 2 && insuranceType != 3 && insuranceType != 4)
{
cout << "Invalid insurance type." << endl;
}
else
{
//Call Functions//
cout << displayInput(employeeNumber, hoursWorked, insuranceType, employeePosition);
cout << displayOutput(grossPay, bonusPay, totalPay, insurance, taxAmt);
}
}
system("pause");
return 0;
}
int calcPay(int hoursWorked, char employeePosition)
{
//Variables
double gp = 0, bp = 0, tp = 0;
int payRate = 0;
//Validate
switch(employeePosition)
{
case 'e':
payRate = 500;
break;
case 's':
payRate = 600;
default:
payRate = 700;
}
//Calculate
gp = hoursWorked * payRate;
if(gp >= 12000)
{
bp = 1000;
}
else if(gp >= 9000)
{
bp = 600;
}
else
{
bp = 0;
}
tp = gp + bp;
return tp;
}
//Calculate Tax
int calcTax(double gp)
{
//Variable
double tax = 0;
//Calculate
if(gp >= 7000)
{
tax = gp * .15;
}
else if(gp >= 4000)
{
tax = gp * .10;
}
else if(gp >= 2000)
{
tax = gp * .05;
}
else
{
tax = gp * 0;
}
return tax;
}
//Calculate Insurance
int calcInsurance(int insuranceType, double gp)
{
//Variables
double ins = 0;
//Calculate
switch(insuranceType)
{
case 1:
ins = gp * .02;
break;
case 2:
ins = gp * .03;
break;
case 3:
ins = gp * .04;
break;
default:
ins = gp * .05;
}
return ins;
}
//Display Input
int displayInput(int employeeNumber, int hoursWorked, int insuranceType, char employeePosition)
{
cout << "\n";
cout << "Employee Number: " << employeeNumber << endl;
cout << "Employee Position: " << employeePosition << endl;
cout << "Employee Hours Worked: " << hoursWorked << endl;
cout << "Employee Insurance Type: " << insuranceType << endl;
cout << "\n";
cout << "************************************\n\n";
return employeeNumber;
}
//Display Output
int displayOutput(double gp, double bp, double tp, double ins, double tax)
{
//Variables
double ss = 0 , medical = 100, netPay = 0, td = 0;
//Calculate
ss = gp * .05;
td = tax + ss + medical + ins;
netPay = gp - td;
//Display
cout << "Employee Gross Pay: " << gp << endl;
cout << "Employee Bonus Pay: " << bp << endl;
cout << "Employee Total Pay: " << tp << endl;
cout << "\n";
cout << "Employee Ins. Amount: " << ins << endl;
cout << "Employee Tax Amount: " << tax << endl;
cout << "Employee S. S. Amount: " << ss << endl;
cout << "Employee Medical Cost: " << medical << endl;
cout << "Employee Total Deductions: " << td << endl;
cout << "\n";
cout << "Employee Net Pay: " << netPay << endl;
return netPay;
}
Apr 30, 2010 at 10:03pm UTC
I'm not really sure what you mean there.
Is there some error you're getting when you simply call:
displayOutput(<passing in 5 doubles>);
?
May 1, 2010 at 12:14am UTC
Actually, I don't know with 100% certainty what you mean either.
First, could you please use [code] tags?
And second, you do (not) need to list the name of the argument in your declarations.
-Albatross
P.S.- (The initial number of Dalmatians) * 3 posts and counting
Last edited on May 1, 2010 at 1:23am UTC
May 1, 2010 at 12:35am UTC
Sorry, I should have been clearer. I'm a student and I'm having trouble figuring out how to call displayOutput in my main function. Here is the entire program.
#include<iostream>
#include<iomanip>
using namespace std;
//Function Prototypes
//Calculate Pay
int calcPay(int, char);
//Calculate Tax
int calcTax(double);
//Calculate Insurance
int calcInsurance(int, double);
//Display Input
int displayInput(int, int, int, char);
//Display Output
int displayOutput(double, double, double, double, double);
int main()
{
//Declare Variables
int employeeNumber = 0, hoursWorked = 0, insuranceType = 0;
char employeePosition;
double grossPay = 0, bonusPay = 0, totalPay = 0, insurance = 0, taxAmt = 0;
//Get employee number and verify whether or not they wish to continue
cout << "Enter your employee number (enter 0 to quit): ";
cin >> employeeNumber;
if(employeeNumber == 0)
{
system("pause");
return 0;
}
//Get hours worked
cout << "Enter your hours worked: ";
cin >> hoursWorked;
//Get employee position and employee insurance type and verify
cout << "Enter your position (e for employee, s for supervisor, m for manegment): ";
cin >> employeePosition;
if(employeePosition != 'e' && employeePosition != 's' && employeePosition != 'm')
{
cout << "Invalid position please enter e, s, or m." << endl;
}
else
{
cout << "Enter your insurance type (1-4): " << endl;
cin >> insuranceType;
if(insuranceType != 1 && insuranceType != 2 && insuranceType != 3 && insuranceType != 4)
{
cout << "Invalid insurance type." << endl;
}
else
{
//Call Functions//
cout << displayInput(employeeNumber, hoursWorked, insuranceType, employeePosition);
cout << displayOutput(grossPay, bonusPay, totalPay, insurance, taxAmt);
}
}
system("pause");
return 0;
}
int calcPay(int hoursWorked, char employeePosition)
{
//Variables
double gp = 0, bp = 0, tp = 0;
int payRate = 0;
//Validate
switch(employeePosition)
{
case 'e':
payRate = 500;
break;
case 's':
payRate = 600;
default:
payRate = 700;
}
//Calculate
gp = hoursWorked * payRate;
if(gp >= 12000)
{
bp = 1000;
}
else if(gp >= 9000)
{
bp = 600;
}
else
{
bp = 0;
}
tp = gp + bp;
return tp;
}
//Calculate Tax
int calcTax(double gp)
{
//Variable
double tax = 0;
//Calculate
if(gp >= 7000)
{
tax = gp * .15;
}
else if(gp >= 4000)
{
tax = gp * .10;
}
else if(gp >= 2000)
{
tax = gp * .05;
}
else
{
tax = gp * 0;
}
return tax;
}
//Calculate Insurance
int calcInsurance(int insuranceType, double gp)
{
//Variables
double ins = 0;
//Calculate
switch(insuranceType)
{
case 1:
ins = gp * .02;
break;
case 2:
ins = gp * .03;
break;
case 3:
ins = gp * .04;
break;
default:
ins = gp * .05;
}
return ins;
}
//Display Input
int displayInput(int employeeNumber, int hoursWorked, int insuranceType, char employeePosition)
{
cout << "\n";
cout << "Employee Number: " << employeeNumber << endl;
cout << "Employee Position: " << employeePosition << endl;
cout << "Employee Hours Worked: " << hoursWorked << endl;
cout << "Employee Insurance Type: " << insuranceType << endl;
cout << "\n";
cout << "************************************\n\n";
return employeeNumber;
}
//Display Output
int displayOutput(double gp, double bp, double tp, double ins, double tax)
{
//Variables
double ss = 0 , medical = 100, netPay = 0, td = 0;
//Calculate
ss = gp * .05;
td = tax + ss + medical + ins;
netPay = gp - td;
//Display
cout << "Employee Gross Pay: " << gp << endl;
cout << "Employee Bonus Pay: " << bp << endl;
cout << "Employee Total Pay: " << tp << endl;
cout << "\n";
cout << "Employee Ins. Amount: " << ins << endl;
cout << "Employee Tax Amount: " << tax << endl;
cout << "Employee S. S. Amount: " << ss << endl;
cout << "Employee Medical Cost: " << medical << endl;
cout << "Employee Total Deductions: " << td << endl;
cout << "\n";
cout << "Employee Net Pay: " << netPay << endl;
return netPay;
}
May 1, 2010 at 1:25am UTC
Oh...
Just call them like any other function. In other words, get rid of the cout <<
from before each of their... callings? Unless you want to print the output of each function as well... wait, you do. Oops.
Really, I see nothing obviously wrong...
-Albatross
Last edited on May 1, 2010 at 1:30am UTC
May 1, 2010 at 3:28am UTC
I manged to get it to display everything except bonus pay and total pay but with it due tonight at 11:55 (and its currently 11:30) I'm out of time.