ask the user if they would like to do something again in c

Solutions on MaxInterview for ask the user if they would like to do something again in c by the best coders in the world

showing results for - "ask the user if they would like to do something again in c"
Leon
09 Jan 2021
1#include<stdio.h>
2int main(){
3int x, y, sum;
4char ch;
5print:
6    printf ("Enter the first number:");
7    scanf ("%d",&x);
8    printf ("Enter the second number:");
9    scanf ("%d",&y);
10    sum=x+y;
11    printf ("\nThe total number is:%d\n",sum);
12again:
13    printf ("\n\t\t\t\t\tDo you want to repeat the operation(Y/N): ");
14    scanf (" %c", &ch);
15
16    if(ch == 'y' || ch == 'Y'){
17        goto print;
18    }
19    else if(ch == 'n' || ch == 'N'){
20        return 0;
21    }
22    else{
23        printf("\n\t\t\t\t\tPlease enter Yes or NO.\n");
24        goto again;
25    }
26   return 0;