※ 引述《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;
}
--
: 想請問一個程式設計的問題
: 題目是說薪水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;
}
--
All Comments