I am writing an objective c program for hangman. I need to replicate another program which has been given to me. I have done most of it, but am having an issue. It has to replic
The loop continue because you are never altering i
and i = 0
is altways true; continue
make that the code jump to the loop condicion, no end the loop. Also, as @AlterMann comments, you are not checking wordLength, i suggest this
bool continueLoop = true;
while (continueLoop ){
printf("\n\n > Please enter a word length: ");
scanf("%i", &wordLength);
printf("\n\n");
if (wordLength > 3 && wordLength < 14) {
continueLoop = false;
}
else {
printf("number must be between 3 and 14 (inclusive)");
}
}
Or maybe use break
and end the loop without flags
while (true){
printf("\n\n > Please enter a word length: ");
scanf("%i", &wordLength);
printf("\n\n");
if (wordLength > 3 && wordLength < 14) {
break;
}
else {
printf("number must be between 3 and 14 (inclusive)");
}
}