100年地特四等程式語言 - 考試
By Zenobia
at 2013-03-31T19:02
at 2013-03-31T19:02
Table of Contents
※ 引述《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;
}
--
Tags:
考試
All Comments
By Kristin
at 2013-04-03T21:44
at 2013-04-03T21:44
Related Posts
關務機械三等…考爆了
By Thomas
at 2013-03-31T18:27
at 2013-03-31T18:27
財政學的外部性
By Zora
at 2013-03-31T17:42
at 2013-03-31T17:42
急! 懇請幫忙解惑數學題~~~萬分感激><
By Connor
at 2013-03-31T17:29
at 2013-03-31T17:29
高點司律函授換上一期?
By Vanessa
at 2013-03-31T16:42
at 2013-03-31T16:42
報名高普考 已逾12萬人
By Ida
at 2013-03-31T15:10
at 2013-03-31T15:10