Tuesday, October 30, 2018

Number Guessing Game

output of random num genrator
output of randome num genrator

// number gussing game
#include<iostream>
#include <cstdlib>
#include<ctime>

using namespace std;
main()
{ // decleration of veriable
int num;
int guess;
bool isGuessed;
num = (rand() + time(0))% 100;
isGuessed = false;
cout<<"\n\t\tNumber Guessing Game"<<endl;
while (!isGuessed)
{
//cout<<"_______________________________________________________________________________"<<endl;
cout << "Enter an integer greater than or equal to 0 but less than 100:  " ;
cin >> guess ;
cout << endl;
if (guess==num)
{
cout<<"************************************************************"<<endl;
cout << "\n\tCONGRATULATION!  you guess the correct number \n." << endl;
cout<<"************************************************************"<<endl;
isGuessed=true;

}
else if (guess<num)
{
cout<<"Ooooopps1!\n\n YOUR GUESS IS LOWER THAN THE NUMBER.\n\n TRY AGAIN :)" << endl;
cout<<"_______________________________________________________________________________"<<endl;
}
else

 {
  cout << "Oh! YOUR GUESS IS HIGHER THAN THE NUMBER.\n\n "<< "GUESS AGAIN :)" << endl;
cout<<"_______________________________________________________________________________"<<endl;
}

}
return 0;


}

3 comments:

  1. what is the purpose of rand() and time()

    ReplyDelete
  2. rand() will genrate a number an arbitrary number.
    time() shows time in nano seconds according to your time calender

    ReplyDelete