help with functions

Hello everyone, I am new to programming and this is my first class. I am having couple of errors. I am not getting the taxRate info correct unless and until the person is making more than 3000. Not sure, what seems to be the problem. Any pointers will be helpful.

thanks





#include <iostream>
#include <conio.h>
#include <string>
#include <iomanip>

using namespace std;

void getInput(string &, int &, double &);
double calculateGrossPay(int, double);
double determineTaxRate(double);
double calculateNetPay(double, double);
void displayOutput(string, double, double, double);




void main()

{
//declare variables
string employeeName;
int hoursWorked = 0;
double hourlyPayRate = 0, grossPay = 0, netPay = 0, taxRate;
int const MAX_EMPLOYEES = 100;
int employeeCount;
bool proceed;
char inputChar;

//display opening message

cout << "Employee Calculator" << endl;

//initialize loop control variable

employeeCount = 0;
proceed = true;

//process employees until user wants to stop or maximum number of employees have been reached

while (proceed = true && employeeCount <= MAX_EMPLOYEES)
{

cout << "Do you want to process employee's pay? " << endl;
cout << "Enter 'Y' to continue, 'N' to stop " << endl;
cin >> inputChar;

if (inputChar == 'Y' || inputChar == 'y')
{

employeeCount = employeeCount + 1;
getInput (employeeName, hoursWorked, hourlyPayRate);
grossPay = calculateGrossPay(hoursWorked, hourlyPayRate);
taxRate = determineTaxRate(grossPay);
netPay = calculateNetPay(grossPay, taxRate);
displayOutput (employeeName, grossPay, taxRate, netPay);


}
else
{
proceed = false;
}
cout << employeeCount << "employees have been processed" << endl;






}


}




void getInput(string &employeeName, int &hoursWorked, double &hourlyPayRate)
{
//get input
cout << "Enter the Employee's name: " << endl;
cin >> employeeName;

cout << "Enter the number of hours worked: " << endl;
cin >> hoursWorked;

cout << "Enter the hourly pay rate: " << endl;
cin >> hourlyPayRate;
}

double calculateGrossPay(int hoursWorked, double hourlyPayRate)
{
//calculate gross pay
double grossPay = 0;
grossPay = hoursWorked * hourlyPayRate;
return grossPay;
}

double determineTaxRate(double grossPay)
{
double taxRate = 0;

if (grossPay < 1500)

taxRate = grossPay * .15;

else if (grossPay < 3000)

taxRate = grossPay * .19;

else if (grossPay < 5000)

taxRate = grossPay * .21;

else if (grossPay < 6000)

taxRate = grossPay * .23;

else

taxRate = .27;

return taxRate;


}


double calculateNetPay(double grossPay, double taxRate)
{
double netPay = 0;
netPay = grossPay * (1 - taxRate);
return netPay;

}


void displayOutput(string employeeName, double grossPay, double taxRate, double netPay)
{
cout << "The gross pay for " << employeeName << " is " << endl;
cout << "Gross Pay: " << grossPay << endl;
cout << "Tax Rate: " << taxRate << endl;
cout << "Net Pay: " << netPay << endl;
}
Last edited on
Firstly, to post code you should use code tags and indent (it's easier on the eyes).

Secondly, your determineTaxRate function is incorrect. The only case that's returning a rate is the else case. Every other case is actually calculating the deduction due to taxes. All those cases conflict with this calculation netPay = grossPay * (1 - taxRate); which expects a number between 0 and 1 for the taxRate.
taxRate = grossPay * .23; i think the problem is there. taxRate is like 200 even though you want it to be 0 - 1. Otherwise really nice code and good to read.
Topic archived. No new replies allowed.