• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Input type cannot be resolved

 
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 




 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 72925
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 47
C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Fire me boy! Cool, soothing, shameless self promotion:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic