Jump to content
  • Advertisement
Sign in to follow this  
Zero_Racer

Check this "Guess the Number" give me input

This topic is 4682 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

can you please tell me how i did on this. #include <iostream> #include <stdlib.h> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); int theNumber = rand() % 100 + 1; int tries = 0, guess; cout << "\tWelcome to Guess My Number\n\n"; do { cout << "Enter a guess: "; cin >> guess; ++tries; if (guess > theNumber) cout << "Too high!\n\n"; if (guess < theNumber) cout << "Too low!\n\n"; } while (guess != theNumber); cout << "\nThats it! You got it in " << tries << " guesses!\n"; system("PAUSE"); return 0; }

Share this post


Link to post
Share on other sites
Advertisement
[ source] and [ /source] tags are your friends. [smile]


#include <iostream>
#include <stdlib.h>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
srand(time(0));

int theNumber = rand() % 100 + 1;
int tries = 0, guess;

cout << "\tWelcome to Guess My Number\n\n";

do
{
cout << "Enter a guess: ";
cin >> guess;
++tries;

if (guess > theNumber)
cout << "Too high!\n\n";

if (guess < theNumber)
cout << "Too low!\n\n";

} while (guess != theNumber);

cout << "\nThats it! You got it in " << tries << " guesses!\n";

system("PAUSE");
return 0;
}



But anyhoo, the game looks good! Maybe an extension would be to allow the use the enter the range the random number will fall in?

Share this post


Link to post
Share on other sites
You're including stdlib twice. Erase "#include <stdlib.h>".

Other than that it looks ok.

Edit: Beaten by 14 seconds.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!