help with functions please

im trying to make a program that uses functions to break up the code blocks but can't figure out what im doing wrong
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// PP4.cpp : main project file.
//James M Snook III
// Program to accept the input and output the data after it been proccessed

	#include "stdafx.h"
	#include <iostream>
	#include <iomanip>
	#include <string>

	using namespace std;

// function prototypes
	int getpay(double& rate);
	int gethrs(double& work);
	int getrate(double& rate, double& work, double& grosspay);
	int calcfica(double& fica, double grosspay);
	int calcfedtax(double& grosspay, double& fed);
	int calcstatetax(double& grosspay, double& state);
	void printstub(string& employee, double& grosspay, double& fica, double& fed, double& state, double& netpay);

int main()
{
//get variables
	string employee;	// employee's name
	double rate;		// employee's rate of hourly pay
	double work;		// employee's hours worked 
	double grosspay;		// employee's before tax pay
	double fica;		// employee's amount of fica paid
	double fed;		// federal tax paid
	double state;		// state tax paid
	double netpay;		// employee's net pay

while (netpay > 0)
	{
	cout << "Employee Name: ";
	cin >> employee;
	int getpay(rate);
	int gethrs(work);
	int getrate(rate, work, grosspay);
	int printstub(employee, grosspay, fica, fed, state, netpay);
	int calcfica(fica, grosspay);
	int calcfedtax(grosspay, fed);
	int calcstatetax(grosspay, state);
	}

system("pause");
return (0);
}

//**************************************************************************************************

int getpay(double& rate)
{
	cout << "hourly rate: ";
	cin >> rate;
	
	// check to make sure that the payrate is between 200
	bool crate = (rate > 200.00 && rate < 5.50)
		while (!crate)
	{
		cout << "pleases enter a hourly rate between $5.50 and $200.00.";
		cin >> rate;
		
	}
		else
		{
			}

	return (rate);
}

//**************************************************************************************************

int gethrs(double& work)
{
	cout << "Hours Worked: ";
	cin >> work;
	
	//Check to make sure that the hours worked are between 0 and 60
	if (work > 60 && work < 0)
	{
		cout << "pleases enter a hours worked  between 0.0 and 60.0.";
		cin >> work;
		}
		else
		{
		}

	return (work);
}

//**************************************************************************************************

int getrate(double& rate, double& work, double& grosspay)
{
// calculate the base pay for an employee
	grosspay = (rate * work);

	return (grosspay);
}

//**************************************************************************************************

int calcfica(double& fica, double grosspay)
{
// Calculate the amount of Fica tax taken out 
	fica = (grosspay *.0765);

	return (fica);
}

//**************************************************************************************************

int calcfedtax(double& grosspay, double& fed)
{
// Calculate the amount of Federal Income tax taken out
	fed = (grosspay * .22);

	return (fed);
}

//**************************************************************************************************

int calcstatetax(double& grosspay, double& state)
{
// Calculate the amount of state tax taken out
	state = (grosspay * .12);

	return (state);
}

//**************************************************************************************************

	void printstub(string& employee, double& grosspay, double& fica, double& fed, double& state, double& netpay)
 {
	netpay = (grosspay - ( fica + fed + state));
	
	//if statement to double check the amount of pay.
	if (netpay > 10000)
	{
		cout << " the Net Pay for " << employee << " is greater then $10,000. Please make sure that " << netpay << " is correct.";
		}
		else
		{
		}
		
		//
	cout << employee << " has earned $" << grosspay << "\nFICA $" << fica << "\nFED $" << fed << "\nSTATE $" << state << "\nNet Pay $" << netpay;

 }



any help you can give is greatly appreciated
What error do you get?
You've got a number of problems:

Lines 37-43 - You don't put the type of the function on a function call.
Line 37: You're passing rate to getpay, but rate is not initialized. Even though you pass it by reference and set it in getpay, this is a poor practice. It's better to use the return value to set rate.
 
 rate = getpay();


Line 58-59: crate will only get calculated once. You need to put the full epxression in the while:
while (rate > 200.00 && rate < 5.50)

Line 69: rate is a double, but you're returning an int. getpay should return a double.

These comments also apply to each of your other get functions.

Line 40: You're calling printstub before you calculate fica, fed tax or state tax.



Topic archived. No new replies allowed.