Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Struggling with the if statement  RSS feed

 
Garren Walter
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, I am very new here. My code is working fine however I need to the option to ask the user if they are sure about their choice using 'char' y for yes and n for no. I have tried several times but have had no luck! ANY help would be greatly appreciated! Thanks in advance.

 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps if you show us what you tried we could point you in the right direction?
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't find any errors in it. Except you seem to have 1R = £17.50 when it should be £1 = 17.50R
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot use myScanner.nextChar() because there ain't no such method.
The nearest you can get to it is myScanner.next().charAt(0)
Beware: You can get nasty errors if you then use nextLine() again. Description here. If you only want single words like Rands/Pounds, try next instead of nextLine.

At this point your code will be much too long to fit into one method; you should have randToPound and poundToRand methods. Also a getOption method, I think. If I wrote it, I would probably use 'y' or 'n' as sentinel values for exiting or continuing a loop. If you don't understand that last sentence, consider whether you should leave that bit until you have been taught about loops.
 
Garren Walter
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that here you promote a ethos of 'let the user figure it out himself', so how do I put it then...I don't know how to put code to confirm the users choice. The question requires that I use 'char'. If I showed you what I tried it will just be a mess.

I don't expect the code but just the method/statements to use.

Thanks again, and like I said I am new to this...
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to do the following things.

* Ask the user to make a choice (you already have this).
* Ask the user if they are happy with their choice. You already have code that asks the user questions so you know how to do this.
* Repeat the two steps above if the user is not happy with the choice they made, so you will need to put the code above in a loop.
* print the conversion that the user chose. You already have this code, but you should only run it when the user confirms they are happy with their choice.
 
Garren Walter
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike, thank you for the input. I will makes some attempts when I get home, appreciate the feedback.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!