Hello, i'm a new learner for Cpp just only one week and currently using JFE and GCC( i was forced to). Here's my following problem: 1)In a program, user is required to enter a five-number digit. So i try this method so that the program only read a FIVE-DIGIT number and keep looping if it's NOT a FIVE-DIGIT number. while (num < 10000 && num > 99999) { cout << "Please enter a five-digit number:\n"; cin >> num; cout << endl; Somehow i failed. is there any simple code for me to slove it? I'm still an ameture. Thx for the concern. p/s: greatly appreciate if someone show me how to do underline in a line of words
well, let's have a look at this. How can a number be.. num < 10000 && num > 99999 && means AND, you will want to use || which means OR. So while the number is less than 10000 OR greater than 99999, keep asking for input Here is a simple example #include <iostream> using namespace std; int main () { int n = 0; while(n < 10000 || n > 99999) { cin >> n; } cout << n << " is 5 digits."; cout << endl; return 0; } Code (markup):