Making the user guess the correct number

So I'm suppose to keep asking the user to guess a number between 1 and 10 until the user enters a 4.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;

int main(){

int userNum = 0;
cout << "Guess a number between 1 and 10: " << userNum;
cin >> userNum;

while ((userNum > 10) && (userNum <= 0)){
	cout << "Please follow the directions!" << endl;
	if (userNum == 4){
		cout << "You guessed it!" << endl;
	}
	if (userNum > 0){
		cout << "Wrong! Try again." << endl;
	}
	if (userNum <= 10){
		cout << "Wrong! Try again." << endl;
	}
}
	

return 0;
}


I keep getting:
Getting a number between 1 and 10: 0_
Press any key to continue

I don't know how to keep it looping till I input 4 and to get rid of the 0 in front of the entered number.
Line 10: How can that while condition ever be true? What number is both > 10 and <= 0 at the same time?

Since the while condition can never be true, you will always fall through to line 24 and exit the program.
Topic archived. No new replies allowed.