Zachary Kang wrote:If possible, I would like to use a for-loop using the number input by the user which is the number of correct answers needed. So something using int numberCorrect =0;
So you want to keep asking the user questions until he/she gets N questions correct, right? So, if the user needs to get 10 questions correct and he hasn't answer 10 correctly even after 30 questions, say he has only been able to answer 4 correct, what happens, do you just keep asking questions until he finally gets 10 correct? You could end up asking 50 questions, right? Or 75, or 103, or ... do you get where I'm coming from?
Zachary Kang wrote:I agree that a while-loop would resonate better with this, however my professor is strictly looking for a for-loop.
An alternative is to use this method. Beware: there are two values for which that method returns the value unchanged. That will probably not be a problem for your current application, however.Junilu Lacar wrote:. . . simplify your code. . . . avoid asking a question where the answer is a negative number. . . .
Campbell Ritchie wrote:
An alternative is to use this method. Beware: there are two values for which that method returns the value unchanged. That will probably not be a problem for your current application, however.Junilu Lacar wrote:. . . simplify your code. . . . avoid asking a question where the answer is a negative number. . . .