if语句可做判断使用比如在游戏中判断用户的等级
大家可做一下比较数字大小是If判断语句中最典型的一个案例。
源码:
// 06-if语句判断.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
int max; int a; int b;
cout << "请输入数字进行比较大小\n";
cin >> a;
cout << "请在次输入数字\n";
cin >> b;
if (a > b)
{
max = a;
cout << "最大的数字为" << max << endl;
cout << "最小的数字为" << b << endl;
}
else
{
max = b;
cout << "最大的数字为" << max << endl;
cout << "最小的数字为" << a << endl;
}
return 0;
}