Making a simple game using c++ if/else and finctions
Simple Game C++
code
#include<iostream>
using namespace std;
void start_game(){
char answer;
int score = 1;
cout<<"What is 1+1"<<endl;
cout<<"(a)= 5"<<endl;
cout<<"(b)= 6"<<endl;
cout<<"(c)= 9"<<endl;
cout<<"(d)= 2"<<endl;
cout<<"choes a option "<<endl;
cin>>answer;
if(answer == 'd'){
cout<<"you choes right answer"<<endl;
cout<<"score::"<<score++<<endl;
}else{
cout<<"You choes wrong Answer"<<endl;
}
cout<<"What is 5+1"<<endl;
cout<<"(a)= 5"<<endl;
cout<<"(b)= 6"<<endl;
cout<<"(c)= 9"<<endl;
cout<<"(d)= 2"<<endl;
cout<<"choes a option "<<endl;
cin>>answer;
if(answer == 'b'){
cout<<"you choes right answer"<<endl;
cout<<"score::"<<score++<<endl;
/*you can add more questions*/
}else{
cout<<"You choes wrong Answer"<<endl;
}
}
void end_game(){
/*cout<<"you can't play "<<endl;
cout<<"Thanks for playing ";*/
}
void game_inst(){
string game_input;
cout<<"First you know game instructions "<<endl;
cout<<"If you want know press 'yes'or 'no'"<<endl;
cin>>game_input;
if(game_input == "yes" ){
cout<<"if you win the game \nyour score +1"<<endl;
cout<<"And you lose the game \nYour score not add"<<endl;
cout<<"<===========0============>"<<endl;
cout<<endl;
start_game();
}else if(game_input == "no"){
cout<<"OK! Enjoy";
start_game();
}
else{
cout<<"sorry you can't play "<<endl;
cout<<"[^_^]THANK YOU [^_^]"<<endl;
end_game();
}
}
int main() {
string user_input;
cout<<"========== WELCOME =========="<<endl;
cout<<"you want to play enter 'play'"<<endl;
cin>>user_input;
if(user_input == "play"){
game_inst();
}else{
end_game();
}
}
Comments
Post a Comment