• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NEED HELP!!!

 
Noah Faust
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my original code




This is what my compiler is saying


C:\Documents and Settings\Noah\My Documents\javastuff>javac Guessthenumber.java
Guessthenumber.java:21: cannot find symbol
symbol : variable y
location: class Guessthenumber
} while (y != rand1);
^
1 error


How can I fix this?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'y' is declared inside the 'do' block, but the value check is outside that block and cannot see the variable.

Try this:

 
fred rosenberger
lowercase baba
Bartender
Posts: 12083
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch! We're glad you dropped in. We have written a guide to help you get the most out of your time here, which I advise you to look over.

Specifically, I'd recommend you start with these two.

Thanks!
 
Noah Faust
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I managed to fix it by changing my loop to this:


if (y == rand1) {
break;
}

} while (true);

Thanks for the help! and sorry about the tag line...
 
Larry Frissell
Ranch Hand
Posts: 82
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Noah,

Just a suggestion regarding the style of your solution. The solution may work, but could be difficult for others to read. Take a look at section 3 of the Ranch Style Guide for some helpful suggestions.
Larry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic