jeudi 30 mars 2017

c++ - having trouble in random numbers

This program generates random numbers and lets the user guess it. I'm using Geany as IDE and it highlights this as an error: Error message: error: 'rand' was not declared in this scope

the_number = rand() % 101 + 1;

Code (not working):

#include <iostream>
using namespace std;
int main()

{
using namespace std;

int the_number;
int guess;
int tries=8;

the_number = rand() % 101 + 1;

cout << "Let's play a game!";
cout << "I will think of a number 1-100. Try to guess it.";
cout << endl;
cin >> guess;

for (tries = 8; tries++;)
{
    if (guess == 8)
    {
        cout << "You guessed it!";
        cout << "And it only took you: "<< tries;
    }
    else if (guess < the_number)
    {
        cout << "Higher";
        tries++;
    }


    else if (guess > the_number)
    {
        cout << "Lower";
        tries++;
    }

    else
         cout << "That's not even in range!";
    return 0;
   }
}




Aucun commentaire:

Enregistrer un commentaire