#include <stdio.h>
#include <stdlib.h>
void main()
{
char choice = 'y';
while(choice != 'n')
{
printf("Enter choice(y/n):- \n");
scanf("%c", choice);
if(choice == 'y')
{
printf("Choice = y");
}
if (choice == 'n')
{
printf("Choice = n");
exit(1);
}
}
}
Actual output:
Enter choice(y/n):-
y
(Program execution terminated)
Expected output:
Enter choice(y/n):-
y
Enter choice(y/n):-
y
Enter choice(y/n):-
n
(Program execution terminated)
I want to ask choice to user until he/she doesn't press 'n'. That's my question.