I'm needing to write a program that gives the user a menu to choose from.
He or she enters a letter for the package they would like. I got the program working great with 'break;' statements. However, the catch is that I'm not allowed to use 'break;' statements, and now I'm entirely stuck. All of the code executes with (a) down without a break, and it's not a linear question, the question asks what kind of car the user would like to buy, so I'm totally stuck as to how to get the same result without 'break;' statements!
(a) Package A
(b) Package B
(c) Package C
(d) Package D
Yes, D is a subset of S, L is a subset of D, P is a subset of L, and B is a subset of P.
I used different letters in my question, but here's what I'm actually dealing with.
The car comes with these different option packages:
Option 'B' is a basic package with the basic features and nothing special.
Option ‘P’ includes, auto transmission, power windows and locks, stereo sound system. cost: base + 1200
Option ‘L’ includes all of the above plus MP3 player, security alarm, cruise control. cost: 600 more than ‘P’
Option ‘D’ includes all of the above plus deluxe detailing, pin stripes, leather seats, cost: 500 more than ‘L’
Option ‘S’ include all the above plus seat heaters, Bose speakers, On Star, steering wheel controls of music system, chrome rims. cost: 800 more than ‘D’
Basically, put the biggest case at the top. Then, going in order of size, list the other cases after them, with no breaks.
1 2 3 4 5 6 7 8
switch (pack)
{
case 0:
cout << "Deluxe features"; // they got deluxe features
case 1:
cout << "Basic features"; // but everybody gets basic features
// the output will always show basic features, but it might also show deluxe
}
@Dicsh... I think zhuge has it the right way around.
@OP: You misunderstand. Each package should list only the things that are introduced in them. So you list everything OTHER THAN "and all the previous package".