|
Simple CPP Game Application To Find Number |
#include
#include
#include
/*
This program plays a simple game.The computer picks a random number
from
0 to 100, and the user tries to guess the number.
*/
const int totchan=7;
void main()
{
int number; //the computer's random number
int guess; //the user's guess
//chanscor stores score for 1successful chance.
int chances=0,score=0,chanscor;
char ans;
do
{ clrscr();
chances=score=0;
cout<<"\nWelcome to the High/Low game.";
cout<<"I will pick a random number from 0 to 100."<>guess;
if((guess<0)||(guess>100))
{
cout<<"Sorry, but your guess "< number)
{
cout<>ans;
}while(ans=='y' || ans=='Y');
}
Sample Output :
Welcome to the High/Low game.I will pick a random number from 0 to 100.
You must try to guess the number.
What is your guess? (0 to 100)
56
56 is high.Try a lower number.
Now you have 6chances left.
What is your guess? (0 to 100)
28
28 is low.Try a higher number.
Now you have 5chances left.
What is your guess? (0 to 100)
36
36 is low.Try a higher number.
Now you have 4chances left.
What is your guess? (0 to 100)
46
46 is high.Try a lower number.
Now you have 3chances left.
What is your guess? (0 to 100)
40
40 is correct. Congratulations!
Your score is 42
Thank you for playing High/Low!
Want to play it again? (y/n)...
|
|
⇓Student Projects⇓
⇑Student Projects⇑ |