I received a chain email (arghhh) recently and I thought I would try and make a program out of this particular one for practice.
The point of the program is to figure out the pattern for a few math riddles and and use the pattern to answer the final math question.
Code:
#include <stdio.h>
int main()
{
int user_input, loop = 1;
char rept;
{
printf("\nTry the following!\n");
printf("\nIf:\n");
printf("3 + 5 = 24\n");
printf("5 + 4 = 45\n");
printf("6 + 8 = 84\n");
printf("\nThen:\n");
}
do
{
{
printf("\n9 + 7 = ");
loop++;
scanf("%d", &user_input);
loop = user_input;
printf("\nWrong! Try Again? (y)es or (n)o: ");
rept = getchar();
getchar();
}
if((rept == 'y') || (rept == 'Y'))
{
continue;
}
else
{
break;
}
}
while(loop != 144);
{
printf("\nCorrect!\n");
}
return 0;
}
The problem is I'm not sure what statement to use if the user selected y or Y.
Code:
if((rept == 'y') || (rept == 'Y'))
{
continue;
}
else
{
break;
}
}
continue; just ends the loop and prints Correct!
I have been advised against using continue; and break; by my lecturer (what are my options?).
I was also told that break; is like force quitting the program, is that true?