void value not ignored as it ought to be

Hey guys! Just relearning c++ and i'm running into this error. I remember addressing it in high school but, that was years ago. Thank you in advanced!

The error is coming up in line 13(srand() issue I think) of the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;

int main(int argc, char *argv[])
{
    int i =1;
    int magic; //computer-generated number
    int guess; //user input

    magic = srand(time(0)) ; //get a random nuber (within the specified type)
    do{
        cout << "Guess the magic number: ";
        cin >> guess;

        if(guess == magic)
        {
            cout << "Correct! The magic number was " << magic << endl;
            cout << "You needed " << i << " tries to guess the number\n";
        }
        else
        {
            cout << "Incorrect..\n";
            if(guess > magic) cout << "Your guess was too high\n";
            else cout << "Your guess was too low\n"; i++;
        }
    } while (guess != magic);
    system("PAUSE");
    return EXIT_SUCCESS;
}


I'm sure it's something really simple that I'm overlooking. I've looked at several solutions but, it seems to apply to that specific code. Please help!
Last edited on
you're mixing up srand with rand.

srand seeds (initializes) the random number generator.
Whereas rand actually produces a random number.

What you want is this:

1
2
3
srand(time(0));  // call exactly once at the start of your program

magic = rand();  // call every time you want a new random number to be generated 
Thank you so much! I knew it was something simple like that. srand turns the engien on, and rand actually drives (to use an analogy of sorts).

So then, what are some other places besides time that srand can seed. could I use an algebraic equation based on user input (variables x, y, etc)? something like srand(x +y)?
Topic archived. No new replies allowed.