This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loops  RSS feed

 
Rose Evans
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys why is this loopinggggggggggggggggggggg over and over when I run it??

 
William A White
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have the line that waits for input commented out, so it's doing exactly what it's been programmed to do. 8^)
 
Rose Evans
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean this line? choice = EasyIn.getInt(); If I uncomment this line..I get this error...

F:\VendingMachine.java:26: cannot resolve symbol
symbol : variable EasyIn
location: class VendingMachine
choice = EasyIn.getInt();
^
1 error

Tool completed with exit code 1
 
William A White
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you want to use a static method from the EasyIn class, but that class is not available to your code. Do you have a .class file for EasyIn? You need to import it into your program if you do.
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is EasyIn ?
It's hard to help when you use methods or classes that we don't have.

When you comment out your line. Choice is always 0. So your while loop will never = 5.
[ May 02, 2005: Message edited by: Hentay Duke ]
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rose Evans:
You mean this line? choice = EasyIn.getInt(); If I uncomment this line..I get this error...

F:\VendingMachine.java:26: cannot resolve symbol
symbol : variable EasyIn
location: class VendingMachine
choice = EasyIn.getInt();
^
1 error


That is because you never declared the variable anywhere... Can't really help you as we can't tell what this variable is supposed to be anyway. But as a guess, it could be a class that reads from the console and returns an int.

As as side note, this question is similar to the way I put together christmas presents. Can't figure out a part, so I just don't use it... and later wonder why the toy isn't working properly...

Henry
 
Rose Evans
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ha ha..thanks guys...with all of you giving me hints...I figured it out...THANKS A MILLION!!!
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For future reference, I have some ideas for what you can do to figure these things out yourself. When I encounter similar problems, I will add System.out.println() calls to print out the values of variables in my program. This allows me to see what the values are set to and compare it with what I think it should be. For example, if you add

at the beginning or end of the while loop in your original code, you would immediately have seen for yourself that it doesn't change. In my opinion, such "debugging output" is very helpful in tracking down problems.

Layne
 
Rose Evans
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone...for such great help and advice....It is greatly appreciated!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!