C程序税公式 [英] C Program Tax Equation
本文介绍了C程序税公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要实现一个printf到旁边的毛重和净重打印屏幕上显示的总税收。我该怎么做呢?
的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;诠释主(){
浮hourlyRate;
浮小时;
浮grossPay;
浮动税;
浮netPay;
浮overTimePayment;
INT lowTax = 0.15;
INT highTax = 0.20; 的printf(请输入时薪:);
scanf函数(%F,&安培; hourlyRate); 的printf(请输入工作时间:);
scanf函数(%F,&安培;小时);
如果(小时< = 40){
grossPay =小时* hourlyRate;
}其他
overTimePayment =(小时 - 40)* hourlyRate * 1.5;
grossPay + = overTimePayment; 如果(grossPay< = 600){ netPay = grossPay - (grossPay * lowTax);
的printf(\\ N低征税净工资= $%2F \\ n,netPay);
}
其他 netPay = grossPay - (grossPay * highTax);
的printf(\\ N高征税净工资= $%2F \\ n,netPay);
的printf(你的工资总额为:%.2lf \\ n,grossPay); 返回0;
}
解决方案
你有你的时间计算倒置,最好是先计算加班费。 (和一些其他错误,请参阅下您的文章评论)
的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
//命名常数
#定义HOURS_PER_WEEK 40
诠释的main()
{
浮hourlyRate;
浮小时;
浮grossPay;
//浮动税;
浮netPay;
浮overTimePayment;
浮lowTax = 0.15;
浮highTax = 0.20; 的printf(请输入时薪:);
scanf函数(%F,&安培; hourlyRate);
// TODO用于检查的工作更多的时间比在一个星期,等等。
的printf(请输入工作时间:);
scanf函数(%F,&安培;小时);
//获取第一加班费(40小时工作周)
如果(小时> HOURS_PER_WEEK){
grossPay = HOURS_PER_WEEK * hourlyRate;
overTimePayment =(小时 - HOURS_PER_WEEK)* hourlyRate * 1.5;
grossPay + = overTimePayment;
}其他{
grossPay =小时* hourlyRate;
}
如果(grossPay< = 600){
netPay = grossPay - (grossPay * lowTax);
的printf(\\ N低征税净工资= $%2F \\ n,netPay);
}其他{
netPay = grossPay - (grossPay * highTax);
}
的printf(\\ N高征税净工资= $%2F \\ n,netPay);
的printf(你的工资总额是:$%2LF \\ n,grossPay);
出口(EXIT_SUCCESS);
}
I need to implement a printf into displaying the total taxes on the print screen next to gross and net. How do I do this?
#include <stdio.h>
#include <stdlib.h>
int main() {
float hourlyRate;
float hours;
float grossPay;
float taxes;
float netPay;
float overTimePayment;
int lowTax = 0.15;
int highTax = 0.20;
printf("Enter the hourly rate: ");
scanf("%f", &hourlyRate);
printf("Enter hours worked: ");
scanf("%f", &hours);
if(hours <= 40) {
grossPay = hours * hourlyRate;
} else
overTimePayment = (hours - 40) * hourlyRate * 1.5;
grossPay += overTimePayment;
if (grossPay <= 600){
netPay = grossPay - (grossPay * lowTax);
printf("\nLow Taxed Net Pay = $%.2f\n", netPay);
}
else
netPay = grossPay - (grossPay * highTax);
printf("\nHigh Taxed Net Pay= $%.2f\n", netPay);
printf("Your gross pay is: %.2lf\n", grossPay);
return 0;
}
解决方案
You had your calculation of the hours upside-down, it is better to calculate overtime first. (and some other errors, see the comments under your post)
#include <stdio.h>
#include <stdlib.h>
// name your constants
#define HOURS_PER_WEEK 40
int main()
{
float hourlyRate;
float hours;
float grossPay;
//float taxes;
float netPay;
float overTimePayment;
float lowTax = 0.15;
float highTax = 0.20;
printf("Enter the hourly rate: ");
scanf("%f", &hourlyRate);
// TODO checks for "worked more hours than are in a week", etc.
printf("Enter hours worked: ");
scanf("%f", &hours);
// get pay for overtime first (40 hour week)
if (hours > HOURS_PER_WEEK) {
grossPay = HOURS_PER_WEEK * hourlyRate;
overTimePayment = (hours - HOURS_PER_WEEK) * hourlyRate * 1.5;
grossPay += overTimePayment;
} else {
grossPay = hours * hourlyRate;
}
if (grossPay <= 600) {
netPay = grossPay - (grossPay * lowTax);
printf("\nLow Taxed Net Pay = $%.2f\n", netPay);
} else {
netPay = grossPay - (grossPay * highTax);
}
printf("\nHigh Taxed Net Pay= $%.2f\n", netPay);
printf("Your gross pay was: $%.2lf\n", grossPay);
exit(EXIT_SUCCESS);
}
这篇关于C程序税公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文