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;
}

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

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:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.