1、标准体重
#include <iostream>
using namespace std;
int main()
{
double h,w,m,n;
cout<<"请输入身高:";
cin>>h;
cout<<"请输入体重:";
cin>>w;
m=h-100;
if(w>1.2*m)
cout<<"您已超重";
else if(w<0.8*m)
cout<<"您的体重偏轻";
else
cout<<"您的体重正常";
}
2、分段函数求值
#include <iostream>
using namespace std;
int main()
{
int x,y;
cout<<"请输入x的值:";
cin>>x;
if(x>=1)
y=x-1;
else
y=1-x;
cout<<y<<endl;
return 0;
}
3、模拟ATM
#include <iostream>
using namespace std;
int main()
{
int m,n;
cout<<"唐氏银行欢迎您"<<endl;
cout<<"请输入密码:";
cin>>m;
if(m==199756)
{
cout<<"1.查询"<<endl;
cout<<"2.取款"<<endl;
cout<<"3.存款"<<endl;
cout<<"4.转账"<<endl;
cout<<"o.退出"<<endl;
cout<<"请选择功能类型:";
cin>>n;
if(n==1)
cout<<"查询";
if(n==2)
cout<<"取款";
if(n==3)
cout<<"存款";
if(n==4)
cout<<"转账";
if(n==0)
cout<<"退出";
}
else
cout<<"对不起,您的密码有误";
return 0;
}