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?
Thanks for reading. ..
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?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

int main()
{
using namespace std;
int num;

cin >> num;

switch (num)
{
case 1-100:    //<<<<<<That's what i was talking about..
cout << //Whatever
break;
}
//etc... .


system("pause");
return 0;    
}


Or an 'if/else if' statement?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

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.

1
2
3
4
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.