Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

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 ("
The total number is:%d
",sum);
again:
    printf ("
					Do 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("
					Please enter Yes or NO.
");
        goto again;
    }
   return 0;
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #user #C
ADD COMMENT
Topic
Name
4+6 =