I just started C++ again, after taking a summer school course on it.
That was a few months back, it's not offered during my normal school day.
I found some sample code from this website to use as my own, personal version of "Hello World!". Mainly used as a refresher.
The problems that I run into with this code, is that when I run this "game", the magic number always happens to be "41".
Code:
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
int number=rand()%100;
int
guess=-1;
int trycount=0;
while(guess!=number && trycount<10)
{
cout<<"Please Enter a Numerical Guess: ";
cin>>guess;
if(guess<number)
cout<<"Sorry, That Number is too low! Please Try again!"<<endl;
if(guess>number)
cout<<"Sorry, That Number is too high! Please Try again!"<<endl;
trycount++;
}
if (guess==number)
cout<<"Congratulations! You correctly guessed the number!";
else
cout<<"Sorry, the correct number was:"<<number;
return 0;
}
41 (for me) is the number that always wins the game. Despite the fact that I used the Random tag. I can't use RAND_MAX because we're not going between 0 and 32767.
Any ideas, anybody?
P.S. If you find the problem, lay out what my code /should/ look like. I'm a noob at this, just resumed from a very long break from it today.
Thanks,
Adam.