Question #262798

The system accepts maximum 2 input of answers for a displayed mathematical question. “WELL DONE” message is displayed for the correct answer and “TRY AGAIN” for the wrong answer. “SORRY. TIME’S UP” message is displayed if both answers are incorrect.


Expert's answer



#include <stdio.h>


int main()
{
    int x=5;
    int y=8;
    int user_sol;
    
    printf("2x+y= ?");
    int sol=2*x+y;
    int count=1;
    while(1){
        printf("\nEnter the solution to the mathematical equation above: ");
        scanf("%d",&user_sol);
        count++;
        if (sol==user_sol){
            printf("\nWELL DONE");
            break;
        }
        else if(sol!=user_sol && count<=2)
        {
            printf("\nTRY AGAIN");
        }
        else{
            printf("\nSORRY. TIME’S UP");
            break;
        }
        
    }


    return 0;
}

LATEST TUTORIALS
APPROVED BY CLIENTS