C
chandra.somesh
I am having trouble understanding why the code given belows enters an
infinite loop when a char is entered instead of an int.
i.e.on subsequent looping ,control doesn't wait for user input and just
keeps printing "Hello" infinitely.
#include<iostream>
using namespace std;
int main()
{
int ch;
while(1)
{
cout<<"Hello";
cin>>ch;
cout<<"You entered "<<ch<<endl;
if(ch==1)
break;
}
return 0;
}
infinite loop when a char is entered instead of an int.
i.e.on subsequent looping ,control doesn't wait for user input and just
keeps printing "Hello" infinitely.
#include<iostream>
using namespace std;
int main()
{
int ch;
while(1)
{
cout<<"Hello";
cin>>ch;
cout<<"You entered "<<ch<<endl;
if(ch==1)
break;
}
return 0;
}