Trouble with String!

I'm having a lot of trouble using string in my program. Once the program runs it asks for a name and then 3 separate numbers. We are just learning about sub functions (or as he puts is programs inside of programs) so that the program has is broken up into steps. Once I input the "name" and "number 1,2 and 3" in the first function, the program calculates the numbers in the second function, and then displays the results as a third and final function; completing the program. The problem I have is in the last step. When the results show, all of the numbers that it calculated show up like they are supposed to but the name does not. It appears as if there is nothing there. It reads as: (I use Bob as any random name)

ABC Company
Employee Payroll Calculator
Please Enter:

Employee Name ==========> Bob

Number of Exemptions ===> 1

Hourly Rate of Pay =====> 12.45

Hours Worked ===========> 20.60


Gross Pay: 256.47
Federal Withholding Tax: 32.4752
Net Pay: 223.995
End Report for




It SHOULD read:



ABC Company
Employee Payroll Calculator
Please Enter:

Employee Name ==========> Bob

Number of Exemptions ===> 1

Hourly Rate of Pay =====> 12.45

Hours Worked ===========> 20.60


Gross Pay: 256.47
Federal Withholding Tax: 32.4752
Net Pay: 223.995
End Report for Bob




There should be the name Bob right after "End Report for". Why doesn't my program bring the name down like it did the numbers???? Please help!!


#include <iostream>
#include <string>

using namespace std;
double Number_of_Exemptions, Hours_Worked, Rate_of_Pay, Gross_Pay, Federal_Withholding_Tax, Net_Pay;

string Employee_Name;

void setup ();
void heading ();
void enter_data ();
void calculate ();
void display_totals ();

int main ()

{

setup ();
heading ();
enter_data ();
calculate ();
display_totals ();

system ("PAUSE");
return 0;

}


void setup ()

{

Gross_Pay = Hours_Worked * Rate_of_Pay;
Federal_Withholding_Tax = 0.16 * (Gross_Pay - Number_of_Exemptions * 53.5);
Net_Pay = Gross_Pay - Federal_Withholding_Tax;

}

void heading ()

{

cout << " ABC Company";
cout << endl;
cout << " Employee Payroll Calculator";
cout << endl;

}

void enter_data ()

{

string Employee_Name;

cout << "Please Enter: ";
cout << endl;
cout << endl;
cout << "Employee Name ==========> ";
cin >> Employee_Name;
cout << endl;
cout << "Number of Exemptions ===> ";
cin >> Number_of_Exemptions;
cout << endl;
cout << "Hourly Rate of Pay =====> ";
cin >> Rate_of_Pay;
cout << endl;
cout << "Hours Worked ===========> ";
cin >> Hours_Worked;
cout << endl <<endl;

}

void calculate ()

{

Gross_Pay = Hours_Worked * Rate_of_Pay;
Federal_Withholding_Tax = 0.16 * (Gross_Pay - Number_of_Exemptions * 53.5);
Net_Pay = Gross_Pay - Federal_Withholding_Tax;


}

void display_totals ()

{

string Employee_Name;

cout << "Gross Pay: " << Gross_Pay;
cout << endl;
cout << "Federal Withholding Tax: " << Federal_Withholding_Tax;
cout << endl;
cout << "Net Pay: " << Net_Pay;
cout << endl;
cout << "End Report for " << Employee_Name;
cout << endl;

}


PLEASE HELP!!!

See this function? Employee_Name has no value. You made it, and then you did nothing with it, so it has no value, and then you output it, but because it's empty, nothing appears on screen.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void display_totals ()

{

string Employee_Name;

cout << "Gross Pay:	 " << Gross_Pay;
cout << endl;
cout << "Federal Withholding Tax:	 " << Federal_Withholding_Tax;
cout << endl;
cout << "Net Pay:	 " << Net_Pay;
cout << endl;
cout << "End Report for " << Employee_Name;
cout << endl;

}
Topic archived. No new replies allowed.