I have this program and I can get everything to work except for the calculation of hours worked. Can someone look at my program and tell me what I have done wrong in using voide functions and reference parameters?
Code:
#include<iostream>
#include<iomanip>
using namespace std;
void initialize(int& a, int& b, char c);
void getHoursRate(double& h, double& r);
double payCheck(double h, double r, double wages);
void printCheck(double& hrs, double& rte, double& wage);
void funcOne(int& d, int& e);
void nextChar(char& t);
int main()
{
int x,y;
char z, ch;
double hours, rate;
double amount;
initialize(x,y,z);
cout<<"After initilialization: x = "<<x<<" y = "<<y<<" z= "<<z<<endl;
cout<<fixed<<setprecision(2);
hours = 0;
rate = 0;
amount = 0;
getHoursRate(hours, rate);
payCheck(hours, rate,amount);
printCheck(hours, rate, amount);
x=35;
y=20;
cout<<"Before calling funcOne x = "<<x<< ", y = "<<y<<endl;
funcOne(x,y);
cout<<"After funcOne: x = "<<x<<endl;
z = 'B';
cout<<"z = "<<z<<endl;
nextChar(z);
cout<<"After nextChar: z = "<<z<<endl;
system ("pause");
cout<<"Press any key to continue "<<endl;
cin.get(ch);
return 0;
}
//function definitions
void initialize(int& a, int& b, char c) //definition of initialize step 1A.
{
a = 0;
b=0;
c = ' ';
}
void getHoursRate(double& h, double& r) //definition of getHoursRate step 1B.
{
cout<<"Enter hours worked: "<<endl;
cin>>h;
cout<<"Enter pay rate: "<<endl;
cin>>r;
}
double payCheck(double h, double r, double wages)
{
if (h > 40.00)
wages = (40.0 * r) +
(1.5 * r * (h - 40.0));
else
wages = h * r;
return wages;
}
void printCheck(double& hrs, double& rte, double& wage)
{
cout<<fixed<<setprecision(0);
cout<<setfill(' ')<<left<<setw(25)<<"Hours worked: "<<right<<setw(10)<<hrs<<endl;
cout<<setfill(' ')<<left<<setw(25)<<"Pay Rate: " <<right<<setw(10)<<"$"<<rte<<endl;
cout<<setfill(' ')<<left<<setw(25)<<"This week's salary: "<<right<<setw(10)<<"$"<<wage<<endl;
}
void funcOne(int& d, int& e)
{
int num;
cout<<"Enter an integer: "<<endl;
cin>>num;
d = (2 * d) + (e - num);
}
void nextChar(char& t)
{
t = 'C';
}
In the void printCheck function I should be able to get the hours worked, the rate of pay and the amount paid. But all I get are zero's. HELP!