Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printf not working  RSS feed

 
Clarence Poma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm in the final stages of working on this workshop. Everything works fine, the code compiles and runs, and takes user input...HOWEVER, it does not display the System.out.printf statements containing the height of the child, it simply acts as though the operation is complete at that point. What am I missing?


 
Cody Biggs
Ranch Hand
Posts: 116
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clarence Poma wrote:
 


Im assuming your using the && incase they do not make a capital letter. You dont need that try this :


That way no matter what the user inputs its always going to be upper case. Now both your if statements will look like this

 
Cody Biggs
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im assuming your using the && incase they do not make a capital letter. You dont need that try this :

*can never get the tags  right


That way no matter what the user inputs its always going to be upper case. Now both your if statements will look like this

 
Clarence Poma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!!! That fixed everything.

[moderation message] removed unecessary quote
 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saving childGender as an uppercase helps here, but you should understand what you were donig wrong in the first place.
The problem was this statement:

This can never be true - childGender cannot ever be both 'M' and 'm' at the same time.
What you wanted was to check whether is was either 'M' or 'm' :
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Another way to sort out the problem with the logical equivalences is to use the predicate algebra which you wanted, rather than what you wrote:-
if (gender == 'm' || gender == 'M')... Note the ||
But what happens if somebody mistakenly enters N as gender? You probably will ignore that problem if you are just beginning, but I would use an enumerated type.That will forever ensure there are only two possible states for Gender and there will be no possibility of anybody using a non-existent gender.

[edit]I notice Fred K has already shown you ||
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!