作者elone (吃大便打线 ...)
看板Examination
标题Re: [考题] 100年地特四等程式语言
时间Sun Mar 31 19:02:47 2013
※ 引述《whiteshirts (MJIB)》之铭言:
: 想请问一个程式设计的问题
: 题目是说薪水40000以上要扣0.05的税金
: 我用C编译器(Turbo C v2.01)执行
: 不管金额输入4万以上或以下都只会出现"Your tax is 0."
: 烦请高手解惑 感谢
: #include <stdio.h>
: main(){
: int salary;
: prinitf("Please input your salary:");
: scanf("%d",&salary);
: if(salary>=40000)
: printf("Your tax is %d.",salary*0.05);
: else
: printf("Your tax is 0.");
: }
: 即使中间if那边改成如下,结果也是一样
: if(salary>=40000){
: salary*=0.05;
: printf("Your tax is %d.",salary);}
: else
: printf("Your tax is 0.");
刚回到家 帮你 重新调整一下
// version 1 如果 salary 用的是 int 那麽你 * 0.05 就不会有小数
#include <cstdlib>
#include <cstdio>
int main()
{
int salary;
printf("Please input your salary:");
scanf("%d",&salary);
if(salary>=40000)
{
salary *= 0.05;
printf("Your tax is %d.",salary);
}
else
{
printf("Your tax is 0.");
}
return 0;
}
//version 2
#include <cstdlib>
#include <cstdio>
int main()
{
// 不好意思 我习惯用double @@
double salary; //如果用float
printf("Please input your salary:");
scanf("%lf",&salary); //这边要改成 %f
if( salary >=40000)
{
salary *= 0.05;
printf("Your tax is %f.",salary);
}
else
{
printf("Your tax is 0.");
}
return 0;
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.254.219.182
1F:推 whiteshirts:谢谢罗 有回文 04/01 14:52