+ 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????
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";
}
+ 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.
+ 2
l just want to know how and where can I use these three dots!
+ 2
I don't think they are used in c++
+ 1
case 10...20.
//too many decimal points.its wrong way declaring case
it should be
case(a>=10 && a<=20)
+ 1
so what case we can use ... ???
+ 1
case "string" :
//for declaring string
case 'char':
//for declaring character
see the difference???
+ 1
I mean when can l use these 3 dots???
+ 1
you can't use them in switch statement.
+ 1
where we can use so????
+ 1
why do you want to use them
+ 1
i think 3 dots are used in python or ruby
but first tell me why do u want to use them
0
this is not like chatting bro... here 3 dots are considered as 3 decimal points which is not possible



