Ending after do while loop
Hi, I've made a guess my number program and it ends straight after the while loop is met. And passes my cout thing after.
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
int guess;
srand(time(0));
int theNumber = rand() % 100 + 1;
int tries = 0;
cout << "Welcome to Ben's Guess My Number game!" << endl;
do
{
cout << "Guess a number in between 0 and 100." << endl;
cout << "Number: ";
cin >> guess;
tries++;
if (guess < theNumber)
cout << "Too low." << endl;
if (guess > theNumber)
cout << "Too high." << endl;
} while (guess != theNumber);
cout << "Congratulations you guessed the number in " << tries << ", well done!" << endl;
cout << "Press the return key to proceed...";
cin.get();
return 0;
}
Thanks :),
Ben