c - why does my netpay display no answer? -
i writing code payroll check. function asks user hours worked , hourly pay. function accepts hours , rate arguments , calculates , returns grosspay. send grosspay function calculate , return payrolltax(.22). call function accept grosspay , taxes arguments , return netpay. last send data function display values (totalhours, hourlyrate, grosspay, tax, , netpay). netpay displaying me 0 , tax displaying wrong answer. can tell me went wrong?
/* payroll check */ #include <stdio.h> float askhoursworked(); float askhourlyrate(); float calculategrosspay(float hours,float rate); float calculatepayrolltax(float grosspay); float calculatenetpay(float grosspay,float tax); float displayallvalues(float ,float ,float,float ,float ); int main() { float hours; float rate; float grosspay; float tax; float netpay; float values; hours=askhoursworked(); rate= askhourlyrate(); tax= calculatepayrolltax( grosspay); netpay= calculatenetpay( grosspay,tax); grosspay=calculategrosspay( hours, rate); values= displayallvalues( hours, rate, tax, grosspay, netpay); return 0; } float askhoursworked() { float hours; printf("\n please enter hours worked \t"); scanf("%f",&hours); return hours; } float askhourlyrate() { float rate; printf("\n please enter payrate \t"); scanf("%f",&rate); return rate; } float calculategrosspay(float hours,float rate) { float grosspay; grosspay=hours*rate; return grosspay; } float calculatenetpay(float grosspay,float tax) { float netpay; netpay=grosspay-tax; return netpay; } float calculatepayrolltax(float grosspay) { float tax; tax=grosspay*.22; return tax; } float displayallvalues(float hours,float rate,float tax,float grosspay,float netpay) { printf("\n total hours %.2f",hours); printf("\n hourly rate %.2f",rate); printf("\n grosspay %.2f",grosspay); printf("\n taxes %.2f",hours); printf("\n netpay %.2f",netpay); }
in c language, use single pass compiler. means here, order matters most. calculating grosspay @ last. , using in calculation of netpay , taxes.
here right way..
hours = askhoursworked (); rate = askhourlyrate (); grosspay = calculategrosspay (hours, rate); tax = calculatepayrolltax (grosspay); netpay = calculatenetpay (grosspay, tax);
check on online compiler
edit have printed output in wrong manner.
printf ("\n total hours %.2f", hours); printf ("\n hourly rate %.2f", rate); printf ("\n grosspay %.2f", grosspay); printf ("\n taxes %.2f", tax); printf ("\n netpay %.2f", netpay);
Comments
Post a Comment