Saturday, 15 November 2014

Guess Game with C++

                     //   Having Problems Executing Program....Comment below

/*            A simple GUESS GAME
*            Compiled Using Turbo C++
*            14/11/2014           ***Hemanth
*/

#include<iostream.h>            
#include<conio.h>   
#include<stdlib.h>
int main()
{
            int guess,Random,i;
            clrscr();
            randomize();
           Random=random(101);
           cout<<"\t\tGUESS GAME\n\t\tguess a number between 0 and 100\n"<<endl;
          for(i=1;i<=5;i++)
         {

                   cout<<"\nEnter your guess"<<endl;
                  cin>>guess;
                  if(guess==Random)
                {
                    cout<<"YOU WON!"<<endl;
                    getch();
                    exit(0);
               }
               if(guess>Random)
                        cout<<"\nSorry,Wrong Guess! Number is less than "<<guess;
              if(guess<Random)
                        cout<<"\nSorry,Wrong Guess! Number is greater than "<<guess;
             cout<<"\tChances Left:"<<5-i<<endl;
        }
 cout<<"\nYour 5 chances are completed.YOU LOST!"<<endl;
 cout<<"\ncorrect GUESS is "<<Random;
 getch();
 return 0;
}

No comments:

Post a Comment