okay. I am very new to to C++ (i just started learning it a week ago). I am making a command-line Final Fantasy quiz. here is my current code for the first question and the stuff at the start.
as you can see, i used the goto statement. however, i would prefer to use a loop or user function. does a for loop NEED 3 parts[ for(initialization; condition; increment) ]?
i just want the condition, as what it checks changes in the loop itself.
I have heard that it is not good to get used to using goto.
a for does need those 3 parts but there a ways round it like just having a part as blank will suffice e.g for(;;;). But if you just want to check the condition a while loop will be better. They take the form: while(condition){//do stuff} .
Goto is generally not liked as far as I know, i suspect it's because they tend to make the code flow not very clear (at least that's what i find), as they allow you to jump to pretty much anywhere in your code.
thankyou Ather. I will probably shorten the code like this eventually, but the are alot of things in there that i do not know about. i don't want to add masses of things i don't actually know how to use (for other things).
however, i did use (a<1 || a>3), which i changed to (q1<1 || q1>3). i don't know why i didn't use this before, as it is something i did know about.
also, with this check, and my original check, and bolo809's check, when i type anything other than a number (in the actual executable), the choose 123 message just continuously appears, causing me to have to exit command prompt. what i wanted was to have it so that if the user accidentally types something other than 1, 2, or 3, for it to ask again.
hello. I am having more problems with this. the fact that any letter I type in or anything other than a number cause an infinite loop. will changing int to char or similar fix this problem.
edit: oops I just double posted. not surposed to do that. haven't used forums in a while. sorry.