兩值比大小
#include <iostream>
using namespace std;
int main()
{
float a,b;
printf("兩值");
scanf("%f %f",&a,&b);
if(a>b)
printf("bigger%.1f\n",a);
else
printf("bigger%.1f\n",b);
system("pause");
return 0;
}
----------------------------------------------------------------------------------------------------------------------
判斷偶數奇數
#include <iostream>
using namespace std;
int main()
{
int n;
printf("input n:");
scanf("%d",&n);
if(n%2==0)
printf("偶數\n");
else
printf("奇數\n");
system("pause");
return 0;
}
-------------------------------------------------------------------------------------------------------------------------
輸入成績
#include <iostream>
using namespace std;
int main()
{
int s;
printf("input score:");
scanf("%d",&s);
if(s>=0 && s<=100) // ! not , && and || or
if(s>=60)
printf("及格\n");
else
printf("不及格\n");
else
printf("輸入錯誤\n");
system("pause");
return 0;
}
----------------------------------------------------------------------------------------------------------------------
輸入里程,並計算出車費。假設里程在1500公尺以下皆為70元,
每超過500公尺加5元,不足500公尺以500公尺計算。
#include <iostream>
using namespace std;
int main()
{
int m,money,diff;
cout<<"里程:";
cin>>m;
if(m<=1500)
money=70;
else
{
diff=m-1500;
if(diff%500==0)
money=70+(diff/500)*5;
else
money=70+((diff/500)+1)*5;
}
cout<<"費用:"<<money<<endl;
system("pause");
return 0;
}
-------------------------------------------------------------------------------------------------------------------------
綜合所得稅速算公式
所得淨額 x 稅率 - 累進差額 = 應納稅額
0 ~ 370,000 x 6% - 0
370,001 ~ 990,000 x 13% - 25,900
990,001 ~ 1,980,000 x 21% - 105,100
1,980,001~3,720,000 x 30% - 283,300
3,720,001 以上 x 40% - 655,300
#include <iostream>
using namespace std;
int main()
{
int salary;
double tax;
cout<<"Input salary:";
cin>>salary;
if(salary<=370000)
tax=salary*0.06;
else if(salary<=990000)
tax=salary*0.13-25900;
else if(salary<=1980000)
tax=salary*0.21-105100;
else if(salary<=3720000)
tax=salary*0.3-283300;
else
tax=salary*0.4-655300;
cout<<"應繳稅額"<<tax<<endl;
system("pause");
return 0;
}
-----------------------------------------------------------------------------------------------------------------------
輸入身高、體重
計算BMI
BMI=體重/身高*身高(M)
BMI<18.5 太輕
18.5<=BMI<24 正常
24<=BMI<27 過重
27<=BMI<30 輕度肥胖
30<=BMI 肥胖
#include <iostream>
using namespace std;
#include <math.h>
int main()
{
double w,h,BMI;
cout<<"身高: 體重:";
cin>>h>>w;
h/=100;
BMI=w/pow(h,2);
cout<<"BMI:"<<BMI<<endl;
if(BMI<18.5)
cout<<"太輕"<<endl;
else if(BMI<24)
cout<<"正常"<<endl;
else if(BMI<27)
cout<<"過重"<<endl;
else if(BMI<30)
cout<<"輕度肥胖"<<endl;
else
cout<<"肥胖"<<endl;
system("pause");
return 0;
}
-----------------------------------------------------------------------------------------------------------------------
輸入時間(分鐘),並計算出停車費。假設停車時間在 30 分鐘
以下免費。超過時間,每半小時為 15 元,不滿半小時以半
小時計算,每日最高以 240 元計算。
輸入值:0 ~ 720 分鐘之間任意值
輸出值:價格
#include <iostream>
using namespace std;
int main()
{
int m,out;
int money=0;
cout<<"輸入時間:";
cin>>m;
if(m>=0&&m<=720)
{
if(m<=30)
cout<<"30分鐘以下免費"<<endl;
else
{
out=m-30;
if(out%30==0)
money=(out/30)*15;
else
money=((out/30)+1)*15;
cout<<"停車金額:"<<money<<endl;
}
if(money>=240)
{
money=240;
cout<<"最高停車費:"<<money<<endl;
}
}
else
cout<<"輸入錯誤"<<endl;
system("pause");
return 0;
}