+ 1

Please run this code and tell me why got this result!!!

#include<stdio.h> int main() { int a = 0; while(a < 20) {//run until a < 20 printf("Do you want to continue?[Y/N]?"); char b; scanf("%c",&b); if(b == 'Y') { printf("Yes\n"); } else { a += 20; //if b != 'Y' break the loop } a++; } return 0; }

4th Oct 2020, 12:35 PM
Phyo Htet Aung
Phyo Htet Aung - avatar
3 Answers
+ 2
What Output u expecting through this program..?
4th Oct 2020, 12:48 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
I expect to enter 'Y' until the end of loop but it stop when I enter the first 'Y'.
4th Oct 2020, 1:18 PM
Phyo Htet Aung
Phyo Htet Aung - avatar
+ 1
I have a try with your code here see https://code.sololearn.com/cB6u4XfV5A2Q/?ref=app
4th Oct 2020, 1:49 PM
HBhZ_C
HBhZ_C - avatar