0

I want to break the loop if the user does not enter any value. How do I do that.

#include<iostream>
using namespace std;

int main()
{

int a=1;
while(a!=NULL) //how do i phrase this. When the user does not enter any input   
//I want the loop to exit
cin>>a;

return 0;
}
3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by jasweb2002
0

Hi;
U have specified that u want to break the loop when the user do not enter any input, but u havent specify for how much time loop will wait for the user input after wich it will break automatially ???u have to specify time limit and use system clock or DELAY function can also be used , but any how u have to specify time........
Fahad

0

Hi;
U have specified that u want to break the loop when the user do not enter any input, but u havent specify for how much time loop will wait for the user input after wich it will break automatially ???u have to specify time limit and use system clock or DELAY function can also be used , but any how u have to specify time........
Fahad

That sums it up pretty well. But if you are in a situation like I was where all user input is instantaneous....

while (cin >> a)
{
}

.. will run till there is no more input. Don't know if that helps at all. :confused:

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.