[Solved] Ask user to repeat the program or exit in C


int main(void) {
float x,y,sum;
char ch;
do {
printf ("Enter the first number:");
scanf ("%f",&x);
printf ("Enter the second number:");
scanf ("%f",&y);
sum=x+y;
printf ("The total number is:%f\n",sum);
printf ("Do you want to repeat the operation Y/N: ");
scanf (" %c", &ch);
}
while (ch == 'y' || ch == 'Y');
}

This uses a do-while loop. It will continue till the condition in the while of the do-while will return false.

In simple words, whenever the user enters y or Y, the while loop will return true. Thus, it will continue.

Check this example and tutorial for do-while loop.

solved Ask user to repeat the program or exit in C