C++编程基础一 29-if语句

匿名 (未验证) 提交于 2019-12-03 00:42:01
 1 // 29-if语句.cpp: 定义控制台应用程序的入口点。  2 //  3   4 #include "stdafx.h"  5 #include <iostream>  6 #include <climits>  7 #include <string>  8 #include <array>  9 #include <math.h> 10 using namespace std; 11  12 int main() 13 { 14     int hp = 0; 15     if (hp <= 0) 16     { 17         cout << "游戏结束" << endl; 18     } 19     //还可以这么写 20     if (hp <= 0) 21         cout << "游戏结束" << endl; //这么写只能默认第一条语句是body 22  23     //if...else语句 24     if (hp <= 0) 25     { 26         cout << "游戏结束" << endl; 27     } 28     else 29     { 30         cout << "游戏继续" << endl; 31     } 32  33     //年龄保护游戏 34     int age = 60; 35         if (age < 18) 36         { 37             cout << "你可以玩3个小时" << endl; 38         } 39         else 40         { 41             if (age < 50) 42             { 43                 cout << "你可以玩10个小时" << endl; 44             } 45             else 46             { 47                 cout << "你可以玩2个小时" << endl; 48             } 49         } 50      51     //if...else if...else 52         if (age < 18) 53         { 54             cout << "你可以玩3个小时" << endl; 55         } 56         else if (age < 50) 57         { 58             cout << "你可以玩10个小时" << endl; 59         } 60         else if (age < 80) 61         { 62             cout << "你可以玩2个小时" << endl; 63         } 64         else  65         { 66             cout << "你不能玩这个游戏" << endl; 67         } 68  69     int t; 70     cin >> t; 71     return 0; 72 }

原文:https://www.cnblogs.com/uimodel/p/9346598.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!