1 //29-if statement. CPP: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <climits>7#include <string>8#include <array>9#include <math.h>Ten using namespacestd; One A intMain () - { - intHP =0; the if(HP <=0) - { -cout <<"Game Over"<<Endl; - } + //you can write it like that. - if(HP <=0) +cout <<"Game Over"<< Endl;//This is the only way to write the first statement is Body A at //if...else Statements - if(HP <=0) - { -cout <<"Game Over"<<Endl; - } - Else in { -cout <<"The game continues"<<Endl; to } + - //Age Protection Game the intAge = -; * if(Age < -) $ {Panax Notoginsengcout <<"you can play for 3 hours ."<<Endl; - } the Else + { A if(Age < -) the { +cout <<"you can play for 10 hours ."<<Endl; - } $ Else $ { -cout <<"you can play for 2 hours ."<<Endl; - } the } - Wuyi //If...else If...else the if(Age < -) - { Wucout <<"you can play for 3 hours ."<<Endl; - } About Else if(Age < -) $ { -cout <<"you can play for 10 hours ."<<Endl; - } - Else if(Age < the) A { +cout <<"you can play for 2 hours ."<<Endl; the } - Else $ { thecout <<"You can't play this game ."<<Endl; the } the the intT; -CIN >>T; in return 0; the}
C + + Programming basics a 29-if statement