ask user to choose with while statment C programming code example

Example: ask the user if they would like to do something again in C

#include<stdio.h>
int main(){
int x, y, sum;
char ch;
print:
    printf ("Enter the first number:");
    scanf ("%d",&x);
    printf ("Enter the second number:");
    scanf ("%d",&y);
    sum=x+y;
    printf ("\nThe total number is:%d\n",sum);
again:
    printf ("\n\t\t\t\t\tDo you want to repeat the operation(Y/N): ");
    scanf (" %c", &ch);

    if(ch == 'y' || ch == 'Y'){
        goto print;
    }
    else if(ch == 'n' || ch == 'N'){
        return 0;
    }
    else{
        printf("\n\t\t\t\t\tPlease enter Yes or NO.\n");
        goto again;
    }
   return 0;

Tags:

C Example