11363人加入学习
(31人评价)
【旧版】C++编程系列 预备季快速上手

旧版课程,制作完成于2017-12-18

价格 免费

条件、判断语句

1.if

2.switch

1.if(if else只能处理2种情况,if else if可以处理多种情况)

int msin(){

//if(false){

//cout<<"if语句"<<endl;

}

//bool isDead=true;

//if(isDead){

//cout<<"游戏结束处理"<<endl;

}

//bool isVip=false;

//if(isVip){

//cout<<"限时打折后的价格"<<endl;

}

//else{

//cout<<"显示正常的价格"<<endl;

}

int vip=1;

if(vip==1){

cout<<"打几折"<<endl;

}

else if(vip==2){

cout<<"打八折"<<endl;

}

else if(vip==3){

cout<<"打七折"<<endl;

}

else {

cout<<"不打折"<<endl;

}

cout<<"if语句之后"<<endl;

return 0;

}

[展开全文]

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;
}
 

[展开全文]

授课教师

SiKi学院老师

课程特色

图文(1)
下载资料(2)
视频(40)