Monday, September 19, 2016

GUESSING GAME :)

Tags

This  C++ Program Generates a Random Number from 0 to 30. Users can make 5 Guesses for that Number. If any of the 5 Guesses match that Random number, a Beep sound is played and you WIN the Game.

#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
void main()
{
int g[5],i=1;
int flag;
clrscr();
cout<<"\tGUESSING GAME \n";

randomize();  //Library Function for Randomization
int num=random(31); //Generates Random Values from 0 to 30

for(i=1;i<=5;i++)
{
cout<<"\nEnter Guess "<<i<<": ";
cin>>g[i];

if(g[i]==num)
{
cout<<"\n\bGuess "<<i<<" is Correct!!";  //  \b for Beep Sound
cout<<"\nWell Done!!";
flag=1;
goto end;
}
else
{
flag=0;
continue;
}
}

end:
if(flag==0)
{
cout<<"\nAll Guesses Are Incorrect!!";
cout<<"\nBetter Luck next Time";
}
getch();
}