user3808597
user3808597

Reputation: 47

Java Cannot Find Symbol Error In Do loop

on the last line of this code Im getting the error that it can't find the symbol wallet. Any help would be greatly appreciated.

int money = money();
boolean again = again("Ready");
do {
    int bet = bet(money);
    int wallet = wallet(bet);
    Deck deck = dealDeck();
    int com = comDeal(deck);
    int user = userDeal(deck);
    int userTotal = userHit(user, deck);
    int comTotal = comHit(com, deck, userTotal);
    int winner = whoWon(userTotal, comTotal);
    again = again("Play again");
}
while (again && wallet > 0);

Upvotes: 0

Views: 1358

Answers (1)

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

int wallet is defined inside the do-while loop. Using it outside of it like in the condition of the while is not allowed since it's out of scope.

Just declare this variable before the do-while loop:

int money = money();
int wallet = 0;
boolean again = again("Ready");
do {
    //rest of code here...
} while (<condition>);

Upvotes: 8

Related Questions