+ 3

use... in switch()

#include <iostream> using namespace std; int main() { int a=0; cin>>a; switch(a) { case 10...20: cout<<"to low!"; break; case 20...30: cout<<"not bad!"; break; default: cout<<"not in cases!"; } return 0; } there is a bug ! [Error] too many decimal points in number what is it meaning????

9th Jul 2017, 3:23 PM
Nafiseh Moghanizadeh
Nafiseh Moghanizadeh - avatar
14 Answers
+ 5
10...20 I assume is a range. Unlike some other languages, c++ does not use these. You're going to have to use if-else-if sentences. if (a >= 10 && a < 20) { cout << "Too low!\n"; } else if (a >= 20 && a <= 30) { cout << "Not bad!\n"; } else { cout << "Not in cases!\n"; }
9th Jul 2017, 7:15 PM
Zeke Williams
Zeke Williams - avatar
+ 5
@Nafiseh, the last time I see three dots used to define a range was years ago, in a Delphi (Pascal) snippet, so I think it's used in such language. This is not supported in C++, you may want to try the sample from @Sreejith or @Zeke instead. I have also been looking for this matter and I think I found the answer here. Thanks everyone.
12th Jul 2017, 4:37 AM
Ipang
+ 2
l just want to know how and where can I use these three dots!
9th Jul 2017, 4:01 PM
Nafiseh Moghanizadeh
Nafiseh Moghanizadeh - avatar
+ 2
I don't think they are used in c++
9th Jul 2017, 6:12 PM
‎ ‏‏‎Anonymous Guy
+ 1
case 10...20. //too many decimal points.its wrong way declaring case it should be case(a>=10 && a<=20)
9th Jul 2017, 3:29 PM
‎ ‏‏‎Anonymous Guy
+ 1
so what case we can use ... ???
9th Jul 2017, 3:33 PM
Nafiseh Moghanizadeh
Nafiseh Moghanizadeh - avatar
+ 1
case "string" : //for declaring string case 'char': //for declaring character see the difference???
9th Jul 2017, 3:38 PM
‎ ‏‏‎Anonymous Guy
+ 1
I mean when can l use these 3 dots???
9th Jul 2017, 3:39 PM
Nafiseh Moghanizadeh
Nafiseh Moghanizadeh - avatar
+ 1
you can't use them in switch statement.
9th Jul 2017, 3:44 PM
‎ ‏‏‎Anonymous Guy
+ 1
where we can use so????
9th Jul 2017, 3:47 PM
Nafiseh Moghanizadeh
Nafiseh Moghanizadeh - avatar
+ 1
why do you want to use them
9th Jul 2017, 3:56 PM
‎ ‏‏‎Anonymous Guy
+ 1
i think 3 dots are used in python or ruby but first tell me why do u want to use them
9th Jul 2017, 3:58 PM
‎ ‏‏‎Anonymous Guy
0
this is not like chatting bro... here 3 dots are considered as 3 decimal points which is not possible
9th Jul 2017, 5:15 PM
Mohit Mehta
Mohit Mehta - avatar