while(ans == 'Y' || 'y')
{
cout<<"--MENU--"<<endl;
cout<<"1.Create a file"<<endl;
cout<<"2.Display that file"<<endl;
cout<<"3.Exit"<<endl;
cout<<"Enter your choice-";
cin>>ch;
switch(ch)
{
case 1:
create(); //create and display functions are written above this, which are not required
break;
case 2:
display();
break;
case 3:
exit(0);
}
cout<<"Do you want the menu again?(Y or y for Yes and anything else for a No)";
cin>>ans;
}
My expectation is:-
When the input is other than Y
or y
in ans
in the last line, the control of the program should exit the loop and execute the next line...
However it executes while loop again. Why?
Suppose if the input is n
in the last line, then the compiler should check whether ans
contains the character Y
or y
and should exit the loop.