Hey
I've only been coding for a couple of days
and I got this code im working on
for some reason the computer only guesses the number 42 instead of a random number
can someone help me?
Heres the code:
/*========================================================================\
|This is basically the guess my number game |
|But the roles are reversed, well I'm going to try it anyway |
|-------------------------------------------------------------------------|
|31/08/2010 - 9:00 started |
|31/08/2010 - 9:51 finished |
|Its slightly flawed as in the random generator only sticks to one number |
|once I learn another method I will update this script |
|-------------------------------------------------------------------------|
|By Chris Forgeard |
|Copyrighted 31/08/2010 |
\========================================================================*/
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
//first ill set up the random number generator etc.
int number = rand() % 100 + 1;
int tries = 0;
char right = 'n';
cout << "Welcome HP MINI, guess my number!" << endl;
//The game loop
while (right == 'n')
{
cout << "Is it " << number << "?" << endl;
cout << "(y/n)" << endl;
cin >> right;
if (right == 'y')
cout << "Yes HP MINI, that is right!" << endl;
if (right == 'n')
cout << "Sorry HP MINI, that is wrong!";
++tries;
}
//The end scene
cout << "Congratulations HP MINI!" << endl;
cout << "You did it in " << tries << " tries!";
cin >> right;
return 0;
}