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;
}

I think that

SYSTEM ("set <variable>=%random%")

should be appropriate... But you'll need to include a file... Stdlib I think.

Edited 6 Years Ago by camthalion95: Errors

Comments
This makes no sense at all.
This article has been dead for over six months. Start a new discussion instead.