an assignment about write a C++ program about gross pay

HELP!!!!!!!!!
Q:
The federal withholding rate and the state withholding rate are based on the following table:
Gross pay Federal withholding rate State withholding rate
0 < Gross pay <= 100 20% 9%
100 < Gross pay <= 250 25% 12%
250 < Gross pay <= 500 28% 15%
500 < Gross pay 32% 18%

Sample output 1: (Contents in bold type are input values)
Enter employee’s name: John Smith
Enter number of hours worked in a week: 10
Enter hourly rate: 9.75

Employee Name: John Smith
Hours Worked: 10.00
Pay Rate: $9.75
Gross Pay: $97.50
Deductions:
Federal Withholding (20%): $19.5
State Withholding (9%): $8.775
Total Deduction: $28.275
Net Pay: $69.225

My Answers:
#include <iostream>

using namespace std;

int main()
{
//Prompt the user to enter employee's name
cout << "Enter employee's name:";
double name;
cin >> name;

//Prompt the user to enter number of hours worked in a week
cout<<"Enter number of hours worked in a week:";
double hours;
cin >> hours;

//Prompt the user to enter hourly rate
cout<<"Enter hourly rate:";
double hourlyrate;
cin >> hourlyrate;

cout << "Employee name:"<< name << "\n"<< "Hours worked:" << hours << "\n"<< "Pay rate:" << hourlyrate << "\n";

//Compute Gross pay
double Grosspay = hours*hourlyrate;
cout << "Gross pay:" << Grosspay << endl;

int FederalWitholdingrate;
int StateWitholdingrate;

if (0 < Grosspay <= 100)
double FederalWitholdingrate = 20%
double StateWitholdingrate = 9%


else if (100 < Grosspay <= 250)
double FederalWitholdingrate = 25%
double StateWitholdingrate = 12%


else if (250 < Grosspay <= 500)
double FederalWitholdingrate =28%
double StateWitholdingrate = 15%

else (500 < Grosspay)
double FederalWitholdingrate = 32%
double StateWitholdingrate = 18%

//Compute
double FederalWitholding=Grosspay*FederalWitholdingrate;
double StateWitholding=Grosspay*StateWitholdingrate;
double TotalDeduction=FederalWitholding + StateWitholding;

cout<< "Federal Witholding (" << FederalWitholdingrate << "):" << FederalWitholding <<endl;
cout<< "State Witholding (" << StateWitholdingrate << "):" << StateWitholding <<endl;
cout<< "Total Deduction:" <<TotalDeduction <<endl;

return 0;
}

but with following error:
main.cpp:33:9: error: expected primary-expression before ‘double’
double StateWitholdingrate = 9%
^~~~~~
main.cpp:52:31: error: ‘FederalWitholding’ was not declared in this scope
double TotalDeduction=FederalWitholding + StateWitholding;
^~~~~~~~~~~~~~~~~
IDK how to fix these errors.Even Idk whether my program is right.
As a beginner, these questions drive me crazy.
If you know, please tell. I really appreciate that!!
Thank you for your time!!
Last edited on
You need to express all your percentages in numeric terms, which are as fractions of 100.

So
double StateWitholdingrate = 9.0 / 100.0

Don't write
double StateWitholdingrate = 9 / 100
Well, you could try it, just so you know what kind of a surprise you're in for if you do it by mistake later on.
I'm still a beginner as well, and my answer may not be correct, but I know you definitely need to brush up on simple syntax. If anyone wants to add to this answer, please do. I'm learning as well.

1
2
3
4
5
6
int main()
{
//Prompt the user to enter employee's name
cout << "Enter employee's name:";
double name;
cin >> name;


1. double name does not make sense here. We are asking the user to input a number of characters together to form a string. Therefore, we should create a string called name.

1
2
3
4
5
6
int main()
{
//Prompt the user to enter employee's name
cout << "Enter employee's name:";
string name = "";
cin >> name;



2. You are missing a lot of semicolons after your statements. And brackets in your if statements. Also, change the percentages to decimal values.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if (0 < Grosspay <= 100)
double FederalWitholdingrate = 20%
double StateWitholdingrate = 9%


else if (100 < Grosspay <= 250)
double FederalWitholdingrate = 25%
double StateWitholdingrate = 12%


else if (250 < Grosspay <= 500)
double FederalWitholdingrate =28%
double StateWitholdingrate = 15%

else (500 < Grosspay)
double FederalWitholdingrate = 32%
double StateWitholdingrate = 18%


Change that to:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        if (grosspay < 100)
        {
		fed_hold = .2;
		state_hold = .09;
	} 
        else if (grosspay > 100 && grosspay <= 250)
       {
		fed_hold = .25;
		state_hold = .12;
	} 
        else if (grosspay > 250 && grosspay <= 500)
       {
		fed_hold = .28;
		state_hold  = .15;
	} 
        else if (grosspay > 500)
       {
		fed_hold = .32;
		state_hold = .18;
	}



I didn't finish the entire program. I just hope you find it useful.

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
#include <iostream>

using namespace std;

int main()
{

	string name = "";
	double hours, hourlyrate;
//Prompt the user to enter employee's name

	cout << "Enter employee's name: ";
	cin >> name;

//Prompt the user to enter number of hours worked in a week
	cout<<"Enter number of hours worked in a week: ";
	cin >> hours;

//Prompt the user to enter hourly rate
	cout<<"Enter hourly rate: ";
	cin >> hourlyrate;

	cout << endl;

	cout << "Employee name:"<< name << "\n"<< "Hours worked:" << hours << "\n"<< "Pay rate:" << hourlyrate << endl;


//Compute Gross pay
	double grosspay = hours * hourlyrate;
	cout << "Gross pay:" << grosspay << endl;

//Federal Withholding rate

	double fed_hold;
	double state_hold;

	if (grosspay < 100){
		fed_hold = .2;
		state_hold = .09;
	} else if (grosspay > 100 && grosspay <= 250){
		fed_hold = .25;
		state_hold = .12;
	} else if (grosspay > 250 && grosspay <= 500){
		fed_hold = .28;
		state_hold  = .15;
	} else if (grosspay > 500){
		fed_hold = .32;
		state_hold = .18;
	}

	double fed_total = fed_hold * grosspay;
	double state_total = state_hold * grosspay;
	double total_deduction = fed_total + state_total;

	cout << "Deductions:" << endl;
	cout << "Federal Withholding : " << fed_total << endl;
	cout << "State Withholding : " << state_total << endl;
	cout << "Total Deduction : " << total_deduction << endl;
	cout << "Net pay : $" << grosspay - total_deduction << endl;

return 0;
}
Oh my god!
I know where I went wrong.
I will try to fix them according to your suggestions!!
Thank you guys so much!!!!!
Well, I fix the problems.
And it works well.
But the only problem is that I cannot input the full name of employees, such as "John Smith".

When I input John Smith, tt will suddenly jump out all words and automatically become like this:

Enter employee's name: John Smith
Enter number of hours worked in a week: Enter hourly rate:
Employee name:John
Hours worked:0
Pay rate:2.07443e-317
Gross pay:0
Deductions:
Federal Withholding(20%): $0
State Withholding (9%): $0
Total Deduction : $0

Has anyone know why this happened? And how to fix it?
Thank you sooo much!!
Topic archived. No new replies allowed.