Write a program which requests a person\'s gross salary, allowed deduction amoun
ID: 3648296 • Letter: W
Question
Write a program which requests a person's gross salary, allowed deduction amount and tax rate. The latter is entered as an integer (like 25), but used as a percentage (.25). The program calculates the net pay as follows:
tax is calculated by applying the tax rate to the gross salary minus the deduction;
net pay is calculated as gross salary minus tax.
Your program should print the gross salary, tax deducted, net pay and the effective tax rate, which is the percentage of the gross salary that was paid as tax.
Your output must follow the format shown in the sample execution below. User input is underlined and will, of course, be different each time the program is run.
Enter gross salary: 60000 Amount of deductions: 12000 Tax rate: 25
Gross salary: 60000.00 Tax deducted: 12000 Net pay: 48000.00 Effective tax rate: 20%
--------------------------------------------------------------------------------------------------------
I'm not sure what I'm doing wrong. I keep getting zeros when I change the type to double but when I use int it works fine... Please help!
#include <stdio.h>
int main()
{
double salary, deductions, net;
double rate;
printf("Enter gross salary: ");
scanf("%lf", &salary);
printf("Amount of deductions: ");
scanf("%lf", &deductions);
printf("Tax rate: ");
scanf("%lf", &rate);
net = (salary - deductions);
//rate = (rate * 0.01);
//output
printf("Gross salary: %lf ", salary);
printf("Tax deducted: %lf ", deductions);
printf("Net pay: %lf ", net);
//printf("Effective tax rate: %.2lf ", );
return 0;
}
Explanation / Answer
You need to typecast the double You are using double/int division hence you get zeros
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.