### 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?
 ``123456789101112131415161718192021222324252627282930313233343536373839`` `````` #include 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.