Guess the
number game
#include <iostream>
#include <stdlib.h>
#include <time.h>
//Author Thejas
using namespace std;
int generateRandomNumber();
int main()
{
srand(time(NULL));
int secret = generateRandomNumber();
int inputVar = -1;
cout<<"~~~~~~~~~~~Guess the Magic Number Game
(1 to 100)~~~~~~~~~~~"<<secret<<endl;
do
{
cout<<"Enter the number "<<endl;
if(!(cin>> inputVar))
{
cout<<"You should
only enter integers between 1 to 100"<<endl;
cin.clear();
cin.ignore(1000,'\n');
}
else if(inputVar > 100 || inputVar < 1)
{
cout<<"You should
only enter integers between 1 to 100"<<endl;
cin.clear();
cin.ignore(1000,'\n');
}else if(inputVar > secret)
{
cout<<"The secret
number is lesser"<<endl;
}else if(inputVar < secret)
{
cout<<"The secret
number is greater"<<endl;
}else{
cout<<"You have fount
the Secret number "<<secret<<endl;
cout<<"Fireworks
Busrsting!!!!!!!"<<endl;
break;
}
}while(true);
return 1;
}
int generateRandomNumber()
{
int randomNum = (rand()%100)+1;
return randomNum;
}
|
No comments:
Post a Comment