### How can you put a range between 2 numbers in C++?

Hello, I am a beginner in C++ and have been practicing for about a week..
---------------------------------------------
This is a truly basic question..
How can you put a range between 2 numbers in C++?
e.g. 1-10
(I tried but didn't work for a reason)
Is that even possible and how? Help, Anyone?
Last edited on
I'm sorrry, but I'm not understanding your question.
What do you mean by "put a range between 2 numbers"?
What I am trying to say is, how can I do for example:

'1-100' at once,
instead of going through all the numbers :
'1, 2, 3, 4, ...56, 57, 58, 59, 60...98, 99, 100'

Can you do this with a 'Switch' statement?
 ``123456789101112131415161718192021`` ``````#include int main() { using namespace std; int num; cin >> num; switch (num) { case 1-100: //<<<<<

Or an 'if/else if' statement?
 ``123456789101112131415161718`` ``````#include int main() { using namespace std; int num; cin >> num; if(num = 1-100) cout << //Whatever //etc... . system("pause"); return 0; }``````

That's it..Do I have to go through all numbers?
Its possible. Use the 'and' operator together with 'greater than' and 'less than' operators.

 ``1234`` ``````if(num >= 1 && num <= 100) //This checks whether number is between 1 - 100 { //Do something }``````
Last edited on
Oh.., Okay read about the 'and' operator many times, but didn't realize it..till now.
Thanks a lot..Really appreciate it
Topic archived. No new replies allowed.