Error in Simple Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deanm007
    New Member
    • Apr 2010
    • 37

    Error in Simple Program

    In the program below, 1 and 1000 are not included as a valid number. Why is it that when I enter 1 or 1000, the program does not say "enter a valid number"? It just ends the program. Help is appreciated. thanks

    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
    	int iX;
    	
    	do {
    		cout << "Enter a Number between 1 and 1000." << endl;
    		cin >> iX; 
    
    	if ( iX < 1 || iX > 1000) {		
    		cout << "Enter Valid number. Try Again." << endl;
    		}
    	}while (1 > iX || iX > 1000); 
    
    	return 0; 
    
    }
    Last edited by Banfa; Apr 18 '10, 11:03 PM. Reason: Added [code] ... [/code] tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    If the program is not doing what you require the error is in lines 12 and 15. Run the program logic yourself with the values 1 and 1000 (and 0, 2, 999, 1001) and you will understand what the problem is and be able to correct your conditionals to achieve what you desire.

    Comment

    • Deanm007
      New Member
      • Apr 2010
      • 37

      #3
      I over looked that one...It needs an = sign on both the lines u mentioned.Thank s a lot Banfa

      Comment

      Working...