make a game in which a number is randomly chosen. then the user types any no. if the is larger it displays "larger"and similarly smaller.You have only 10 guesses.If the number is guesed It should display "WINNER"
Pleez help me if u know the answer
also tell me from where I can download C++ which runs as a dos program.
C++ help....................!!!!!!...
i will give you a site that i am using as a refference of my projects..... Try it and search for guessing game and choose the C++ language.... Hope it will help you....
Reply:#include %26lt;iostream%26gt;
#include %26lt;ctime%26gt;
using namespace std;
int main()
{
cout %26lt;%26lt; "enter a number: ";
int guess;
cin %26gt;%26gt; guess;
srand(time(0));
int num = rand() % 100;
int guesses = 1;
while (guess != num %26amp;%26amp; guesses != 10) {
if(guess %26gt; num)
cout %26lt;%26lt; "larger" %26lt;%26lt; endl;
if(guess %26lt; num)
cout %26lt;%26lt; "smaller" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
guesses++;
}
if(guess == num)
cout %26lt;%26lt; "WINNER" %26lt;%26lt; endl;
else
cout %26lt;%26lt; "the number was " %26lt;%26lt; num %26lt;%26lt; endl;
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment