if 语句
方法一:
#include<iostream>
using namespace std;
int main() {
//程序流程结构
//顺序结构、选择结构、循环结构
//选择结构if语句
int score = 750;
cout << "请输入您的高考分数:" << endl;
cin >> score;
cout << "您的高考分数为:" << score << endl;
if (score >= 600)
{
cout << "恭喜您考上一本大学!" << endl;
}
else if (score >= 500)
{
cout << "恭喜您考上二本大学!" << endl;
}
else if (score >= 400)
{
cout << "恭喜您考上三本大学!" << endl;
}
else
{
cout << "遗憾您未考上一本大学......" << endl;
}
system("pause");
return 0;
}
方法二:
#include<iostream>
using namespace std;
int main() {
//程序流程结构
//顺序结构、选择结构、循环结构
//选择结构if语句
int score = 750;
cout << "请输入您的高考分数:" << endl;
cin >> score;
cout << "您的高考分数为:" << score << endl;
if (score > 400)
{
if (score >= 500)
{
if (score >= 600)
{
cout << "恭喜您考上一本大学!" << endl;
}
else
{
cout << "恭喜您考上二本大学!" << endl;
}
}
else
{
cout << "恭喜您考上三本大学!" << endl;
}
}
else
{
cout << "遗憾您未考上一本大学......" << endl;
}
system("pause");
return 0;
}
比较三个数的大小
#include<iostream>
using namespace std;
int main() {
//将输入的三个数按照由大到小排序
int a, b, c;
cout << "请输入三个需要比较的数:" << endl;
cin >> a;
cin >> b;
cin >> c;
cout << "a = " << a << "\n" << "b = " << b << "\n" << "c = " << c << endl;
if (a > b)
{
if (a > c)
{
if (b > c)
{
cout << "a > b > c" << endl;
}
else
{
cout << "a > c > b" << endl;
}
}
else
{
cout << "c > a > b" << endl;
}
}
else
{
if (a > c)
{
cout << "b > a > c" << endl;
}
else if(c > b)
{
cout << "c > b > a" << endl;
}
else
{
cout << "b > c > a" << endl;
}
}
system("pause");
return 0;
}