Total rookie here. I did the Cola Machine exercise and without the "else" statement it works fine but I wanted to add a response for incorrect inputs.
So with what you see below it works if you select 5 or any number above 5 but selecting 1-4 will give the soda choice string as well as my bad selection string. So I tried putting the "else" after each "if" but that didn't work.
Heh, I was about to ask if I need to if (answer >= 6) tried it real quick and it works fine. Is that the optimal way to do it? is it possible with an "else"? I thought "else" would be ideal because it would cover anything someone input other than 1-5.
Now to go read about switches and make it work with that
I'm open to any constructive criticism to help me learn. I'm having a lot of fun with it and looking forward to seeing what I can build for fun.
Thank you. So if I wasn't going to do the "else" at the end is it wrong to use all "if" statements the way I did, should it always be
if
else if
else if
?
No, it isn't wrong. It depends on how small your project is, you may decide to use if statement for everything or you may choose the method I wrote above. They are both "legal".