geronimo Finch wrote:Okay. I have a question on this. I have to ask how many children's tickets you want to order. When I apply the code below, it just accepts whatever I input, including letters. I imagine it is to do with setting childrensTickets = 0? If I input a letter using the below it accepts - shouldn't it print the error given the input is not >=0?
Nope, because if the Scanner doesn't have a "next Int" (and a letter isn't an Int), you set the value to 0 yourself and then check 'if (childrensTickets >=0)'.
So, is 0 >= 0?
You tell me what happens next...
BTW: You could help yourself (and us) out a lot by indenting your code properly.
That's where I'm confused. I'm unsure what to set 'childrensTickets' to. I know it shouldn't be '=0' but what else should I set it to? Or am I way off track here? Do I need to set it to something?
Note the trick with the loop doesn't work for files, only for keyboard input.
What I want to know now is if I can input a line after this piece of code:
similar to something like '(if adultTickets ==0) print below
else If (adultTickets >0) to skip the above and go to the this segment:
So basically contingent on the adultTickets input I want to perform an if/else with these two different segments but is that possible and where do the brackets go, do they need to cover each entire piece of code?
*Just to clarify, adults and student/OAPS can't both go. Only one of each. Adults is one group and student/OAPS is another group.