- Joined
- May 14, 2022
- Messages
- 2
- Reaction score
- 0
#include <stdio.h>
#include <conio.h>
int main()
{
int a;
char ch = 'c';
while (ch == 'c')
{
printf ("Enter a digit 0 - 9:\n");
scanf("%d", &a);
switch (a)
{
case 0 : printf("Zero\n");
break;
case 1 : printf("One\n");
break;
case 2 : printf("Two\n");
break;
case 3 : printf ("Three\n");
break;
case 4 : printf("Four\n");
break;
case 5 : printf("Five\n");
break;
case 6 : printf("Six\n");
break;
case 7 : printf("Seven\n");
break;
case 8 : printf("Eight\n");
break;
case 9 : printf("Nine\n");
break;
default : printf("Illegal character\n");
}
printf ("Enter 'c' if you want to continue\n");
printf("Or any other character to end\n");
scanf("%c", &ch);
if (ch != 'c');
printf("End of session\n");
}
}
The program was ending was coming out of the loop after the first output, It was not taking input for the continue or end of session. Please help to find the mistake.
#include <conio.h>
int main()
{
int a;
char ch = 'c';
while (ch == 'c')
{
printf ("Enter a digit 0 - 9:\n");
scanf("%d", &a);
switch (a)
{
case 0 : printf("Zero\n");
break;
case 1 : printf("One\n");
break;
case 2 : printf("Two\n");
break;
case 3 : printf ("Three\n");
break;
case 4 : printf("Four\n");
break;
case 5 : printf("Five\n");
break;
case 6 : printf("Six\n");
break;
case 7 : printf("Seven\n");
break;
case 8 : printf("Eight\n");
break;
case 9 : printf("Nine\n");
break;
default : printf("Illegal character\n");
}
printf ("Enter 'c' if you want to continue\n");
printf("Or any other character to end\n");
scanf("%c", &ch);
if (ch != 'c');
printf("End of session\n");
}
}
The program was ending was coming out of the loop after the first output, It was not taking input for the continue or end of session. Please help to find the mistake.