Program to find out the number which computer has chosen randomly(Level- Medium)

Program # 11: Game: Find out the Hidden Number

//Program to find out the number which computer has chosen randomly(Level- Medium)
Can use it as a GAME
#include <iostream.h> 
#include <conio.h>
#include <stdlib.h>            //is used for Rand() function

void main ()
{
clrscr();
int n,k,c=0;
k = rand()%100;            //Built in function generate random number cout<<"Computer has selected a number between 0  100 and save it in its memory"<<endl;
in:
cout<<"Enter the number to find out the hidden number = "; cin >>n;

c++;

if (n>k)
cout<<"Your number is greater"<<endl;
if (n<k)
cout<<"Your number is smaller"<<endl; if (n==k)
{
clrscr (); cout<<endl;
cout<<"The number is found"<<endl; 
cout<<"The number is "<<k<<endl;
cout<<"You find out the number after mistakes = "<<c<<endl; 
getch ();
exit(0);          //Stop the working
}
goto in;
}

Post a Comment

0 Comments