Adding statement between loops
If you have a look at the following code:
Code:
#include <stdio.h>
int main()
{
int answer;//users answer input
{
printf("\nIf:");
printf("\n2 + 3 = 10\n");
printf("7 + 2 = 63\n");
printf("6 + 5 = 66\n");
printf("8 + 4 = 96\n");
}
do
{
printf("\nThen:\n");
printf("\n9 + 7 = ");
scanf("%d", &answer);
}
while(answer != 144);//only loops if the answer is anything but 144
return 0;
}
If you compile and run the program, it would look like this:
If:
2 + 3 = 10
7 + 2 = 63
6 + 5 = 66
8 + 4 = 96
Then:
9 + 7 = 27// red only implies its wrong in this example for demonstration purposes'.
Then:
9 + 7 = 144//The program will now end
What I really want is that the program give the statement "Try again y/n?" so the user can opt to try again. Example:
If:
2 + 3 = 10
7 + 2 = 63
6 + 5 = 66
8 + 4 = 96
Then:
9 + 7 = 23
Wrong! Try Again "y" or "n"? //if the answer is y, then the program will loop the same way until the user either types n or gets it right.