do while loop won't terminate

Feb 16, 2013 at 9:03pm
Here's the loop:

1
2
3
4
5
6
7
8
9
10
11
12
13
void feetToM()
{
    int start, end;
    
    do
    {
        cout << "Please enter a starting and ending number of feet to convert:" << endl;
        cin >> start >> end;
    }
    while (start<0 || start<end);

//other stuff
}


When I run the program it keeps outputting the above cout statement, even if I enter valid input. What's the problem?
Last edited on Feb 16, 2013 at 9:12pm
Feb 16, 2013 at 9:11pm
The loop terminate when the condition start<0 || start<end becomes false. Example: start=0, end=-1 will terminate the loop.
Last edited on Feb 16, 2013 at 9:12pm
Feb 16, 2013 at 9:18pm
Oops fixed to while (start<=0 || start>end);. Thanks
Feb 16, 2013 at 9:19pm
Just do

 
while(start < 0)
Feb 16, 2013 at 10:46pm
Use:
while(start<0);
Topic archived. No new replies allowed.