What am I doing wrong?

Clark’s Cafe pays its employees time and a half for every hour worked over 40 hours.
a) Write a program to calculate gross weekly wages (before taxes) given the hours worked and the hourly rate.

I have this part done.

b) Mr. Clark employs students who are exempt from taxes and others who are not.
Modify the program so that if an employee is not exempt, 18% will be deducted
from gross wages, otherwise “NO TAXES DEDUCTED” will be displayed.

This is the part that is confusing me. The program is supposed to look like as shown:
Enter hours worked: 45
Enter hourly rate: 10.00
Exempt (Y/N)? Y
Gross wages = $475.00
NO TAXES DEDUCTED
Enter hours worked: 20
Enter hourly rate: 4.00
Exempt (Y/N)? N
Gross wages = $80.00
Wages after taxes = $65.60

In my program, when the user enters "Y", there should be "NO TAXES DEDUCTED". I keep getting NO TAXES DEDUCTED along with the Wages after taxes. What am I 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
  #include <iostream>

using namespace std;


int main()
{
double hours;
double rate;
char answer;

do {
cout << "Enter hours worked: ";
cin >> hours;
cout << "Enter hourly rate: ";
cin >> rate;
cout << "Exempt (Y/N)? ";
cin >> answer;

if ((hours <= 40) && (answer == 'Y'))
cout << "Gross wages = " << (hours*rate) << endl;

else if (( hours <= 40) && (answer == 'N'))
cout << "Gross wages = " << (hours*rate) << endl;
cout << "Wages after taxes = " << (hours*rate)-((hours*rate))*0.18 << endl;

if ((hours > 40) && (answer == 'N'))
cout << "Gross wages = " << (hours*rate) + ((hours-40)*(rate*0.50)) << endl;


if ((hours > 40) && (answer == 'Y'))
cout << "Gross wages = " << (hours*rate) + ((hours-40)*(rate*0.50)) << endl;

} while (answer != 'Y');
cout << "NO TAXES DEDUCTED";

return 0;
}
"NO TAXES DEDUCTED" will be printed no matter what the user enters as it's at the end of your code and not in any of the conditional tests.

Also, surround your if/else statements in braces. Line 25 will print even if the condition on line23 is not met.

edit: if i was you i would remove the do/while loop and get your tax logic paths sorted out first.
Last edited on
Topic archived. No new replies allowed.