马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 这是她 于 2020-4-23 21:13 编辑
The desire to reach for the stars is ambitious.The desire to reach hearts is wise and most possible.
if if if if if if 可惜没if#include <iostream>
using namespace std;
int main()
{
int road = 1,house = 2,gulf,breek,desert;
char season;
//if 表达式中 1-->true 0-->false
//第一种:只有一个if
if (road)
{
cout << "road = 1" << endl;
road -= 1;
}
//表达式中的结果为true-->执行循环体中的内容;否则-->直接跳过if语句
//第二种:if else
if (house > 0)
cout << "explore the paradise" << endl; //表达式为true执行
else
cout << "a trip to the paradise" << endl;//表达式为false执行
//第三种:if else if else
cout << "Enter a word : ";
cin >> season;
if (season == 'a')//①
cout << "a novel experience" << endl;//if ①的表达式为true,执行此代码
else
if (season == 'b')//②-----if①的表达式为false,执行此代码
cout << "a new perspective" << endl;// ②表达式值为true,执行此代码
else
cout << "the world city" << endl;//②表达式为false,执行此代码
//条件运算符
cout << "Enter two integers : ";
cin >> gulf >> breek;
cout << "The large of " << gulf << " and " << breek ;
int rain = gulf > breek?gulf:breek;//rain的值:先判断gulf>breek true-->执行gulf false-->执行breek
cout << " is " << rain << endl;
//switch语句
cout << "Enter a number(1-4) : ";
cin >> desert;
switch (desert)//括号中相当于一个标签,会跳转到以下对应的代码;标签-->int char 枚举
{
case 1 :
cout << "kicking BeiJing!\n";//desert 为1-->执行此语句
break;
case 2 :
cout << "the oriental pearl!\n";//desert 为2-->执行此语句
break;
case 3 :
case 4 :
cout << "intoxicated in Guizhou!\n";//desert 为 3/4-->执行此语句
break;
default :
cout << "a true escape!";
}
return 0;
}
渣渣一枚大佬们手下留情
可惜没if但你有建议
|