THE C++ CASSINO GAME
In this game computer generates some random number and the task of player is to guess that number in five choices.The program is very easy to be made but it is very addicting and difficult.FOLLOWING IS SOURCE CODE:
----------------------------------------------------------START------------------------------------------------------
#include <iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int x=1;
int n;
int answer;
int main(){
srand(time(0));
answer = rand()%51; //In order to reduce difficuly level of this game change 51 to lesser number.
cout<<"Instructions:YOU HAVE ONLY Five CHANCES TO GUESS THE ANSWER"<<endl<<endl;
cout<<"ENTER NUMBER FROM 0 t0 50"<<endl<<endl; //changing 51 to lesser number
//mean range will reduce to lesser number
while( x<=5){
cout<<"guess your "<<x<<"th choice"<<endl<<endl;
cout<<"YOUR CHOICE NO#"<<x<<"=";
cin>>n;
if(n==answer){
cout<<"WOH MAN! you guessed the right answer"<<endl;
cout<<"CONGRATULATIONS YOU HAVE WON THE CHALLENGE,WOH MAN YOU HAVE BEATEN THE COMPUTER,ARE YOU REALLY A HUMAN??"<<endl;
}
if( n<answer){
cout<<"your guess is too small try some bigger number"<<endl<<endl;
cout<<"You have "<<5-x<<" chances remaining"<<endl<<endl;
}
else{
cout<<"your guess is too big try some smaller number"<<endl<<endl;
cout<<"You have "<<5-x<<" chances remaining"<<endl<<endl;
}
x++;
}
cout<<"COMPUTER'S GUESS ="<<answer<<endl;
}
--------------------------------------------------------CLOSE-----------------------------------------------------
#include<ctime>
#include<cstdlib>
using namespace std;
int x=1;
int n;
int answer;
int main(){
srand(time(0));
answer = rand()%51; //In order to reduce difficuly level of this game change 51 to lesser number.
cout<<"Instructions:YOU HAVE ONLY Five CHANCES TO GUESS THE ANSWER"<<endl<<endl;
cout<<"ENTER NUMBER FROM 0 t0 50"<<endl<<endl; //changing 51 to lesser number
//mean range will reduce to lesser number
while( x<=5){
cout<<"guess your "<<x<<"th choice"<<endl<<endl;
cout<<"YOUR CHOICE NO#"<<x<<"=";
cin>>n;
if(n==answer){
cout<<"WOH MAN! you guessed the right answer"<<endl;
cout<<"CONGRATULATIONS YOU HAVE WON THE CHALLENGE,WOH MAN YOU HAVE BEATEN THE COMPUTER,ARE YOU REALLY A HUMAN??"<<endl;
}
if( n<answer){
cout<<"your guess is too small try some bigger number"<<endl<<endl;
cout<<"You have "<<5-x<<" chances remaining"<<endl<<endl;
}
else{
cout<<"your guess is too big try some smaller number"<<endl<<endl;
cout<<"You have "<<5-x<<" chances remaining"<<endl<<endl;
}
x++;
}
cout<<"COMPUTER'S GUESS ="<<answer<<endl;
}
--------------------------------------------------------CLOSE-----------------------------------------------------
EmoticonEmoticon