Block if else statement
#include <stdio.h>
int main(void)
{
int answer, i;
int again;
for(i = 1; i < 11; i++) {
printf("What is %d + %d? ", i, i);
scanf("%d", &answer);
if(answer == i + i)
printf("Right!\n");
else {
printf("Wrong\n");
printf("Try again.\n ");
printf("\nWhat is %d + %d? ", i, i);
scanf("%d", &answer);
/* nested if */
if(answer == i + i)
printf("Right!\n");
else
printf("Wrong, the answer = %d\n", i + i);
}
}
return 0;
}
Related examples in the same category