I have been following Bucky's Tutorial on Youtube and I am up to 25 which is switches.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
usingnamespace std;
int main()
{
int age;
cin >> age;
switch(age)
{
case // Trying to add more than one number here so it can read 10-20 or something like that
cout <<"It worked!";
}
}
So there is no way to do like case 10 - 20 except for adding a new case each time? That is annoying D;. I guess I'll use an If statement instead, and for return 0; you do not need it since the program assumes it will return 0. At least for Code::Blocks anyways.
Close, but unlike us human's representation for a range, C++ works a little differently:if(10 <= age && age <= 20)
And yes, when it comes to ranges, prefer the good 'ol if-else.