While loop && "was not declared in this scope" error

I have this code that works fairly well, but depending if I put an extra while loop or not I get errors:
hw7.cpp:34: error: ‘selected’ was not declared in this scope
hw7.cpp:36: error: ‘first’ was not declared in this scope
hw7.cpp:37: error: ‘second’ was not declared in this scope
hw7.cpp:43: error: ‘second’ was not declared in this scope

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    while(joe.get_money() > 0 && joe.get_money() < 1000)
    {
        while(bet >= 0) //THIS LOOP here
        {
            cout << "You have " << joe.get_money() << endl;
            srand ( (int) time(0) );
            Card first;
            Card second;
            Card selected;
            cout << "You got a " << first.get_rank() << " of " << first.get_suit()
                << " and a " << second.get_rank() <<  " of " << second.get_suit() <<".\n";
            cout << "How much do you want to bet the next card is in between? ";
            cin >> bet;
        }
    }

Why am I getting the error? Is it because the compiler thinks that it might never get to that part of the code?
Not sure but maybe the class isn't set up properly?
Also don't put the srand(int)time(0)); inside the while loop. Put it once at the start of the code or else if you seed it every time it goes through a while loop you will get unwanted results.
If you declare something inside a while, for, if, function, it survives only in that scope.
My guess is that you have
1
2
3
4
5
6
while(bet>=0){
//...
Card first, second, selected;
//...
} //end of scope (first, second and selected die)
first.do_something();


Put the lines that you're getting the errors (34 to 43)
Topic archived. No new replies allowed.