I wouldn't use a switch statement. There are just so many duplicate values. This is much easier to read:
Code:
if(speed < 0 || speed > 30) {
cout << "Go to Jail\n";
}
else if(speed < 5) {
cout << "No fine applies" << endl;
}
else if(speed < 15) {
cout << "The fine is $50" <<endl;
}
else { /* speed < 30 */
cout << "The fine is: $" << speed*10 << endl; break;
}
If you have to use a switch for some reason, you could always conserve vertical whitespace at the cost of horizontal whitespace by putting multiple cases on one line.
Code:
case 0: case 1: case 2: /* ... */