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;
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!!
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.
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!!