• Post Reply Bookmark Topic Watch Topic
  • New Topic

Input type cannot be resolved  RSS feed

 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am receiving the error on line 27 that input "type" cannot be resolved this only happens after I have inserted the do-while loop into the program, any ideas on what may be causing this, as the int variable type is clearly defined the line prior.


 




 
Pete Letkeman
Ranch Foreman
Posts: 907
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are defining type on line 25 inside the loop and then you are trying to use it outside of the loop

On line 27 you are testing against the value declared inside the loop

If you define type before the loop begins you can give it an initial value of 0.
Then you can remove the "int" from line 25.
 
Pete Letkeman
Ranch Foreman
Posts: 907
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realize that you are starting out, but you may want to look into refactoring you code to move the code denoted with //ADD, //SUBTRACT,//MULTIPLY, //DEVIDE and //GENERATE RANDOM NUMBER into separate methods.
Doing this will allow you to separate your code into logical blocks, which can be tested, debugged and programmed separately.
Other benefits of this would code reuse and read ability.

Some people have guidelines that they follow, where if a method is longer then X lines then it's doing too much and it needs to be refactored into different methods.
Some companies enforce the longer then X rule.
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete Letkeman wrote:. . . move the code denoted with //ADD, //SUBTRACT,//MULTIPLY, //DEVIDE and //GENERATE RANDOM NUMBER into separate methods.
. . .
Good point. You have lots of repeated code, for example, several places where you enter each number. Also please delete the comments, tha don't tell us anything which isn't already obvious from reading the code.
 
pankaj saxena
Ranch Hand
Posts: 47
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if you declare variable : 'input' and 'type' at line 10 or after declaring variables : 'input' and 'type' at line 10, then also it is entering in an infinite do..while loop and its keep on asking : "Select the calculation you would like to perform" whether you enter 1 or 2 or  3 or 4 or 5. Therefore you need to consider your do.. while loop properly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!