Public Group

# Check this "Guess the Number" give me input

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

## 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 on other sites
[ 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 on other sites
The only thing that doesnt look right is this:

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

Does that even compile?

##### 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 on other sites
what does \t do i know \n is new line

##### Share on other sites
/t is a tab. it's a different charecter then 5 spaces.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633709
• Total Posts
3013481
×