First, check your placement of that last default clause. It is outside of the switch I think you intended it for, causing it to be executed when you don't want it to be.
In general, your switch statements are somewhat complex. I might suggest a design change, and create a separate method to handle different
case switch statements. You could do something like:
getCar(); //ask for and figure out what car they want
case 's':
case 'S':
determineAge( 'S' );
..etc handle other car cases
the determineAge function will ask user if it's new or old, and depending on the answer to that (using a switch), can call a third function with both parameters: calcCost( 'S', 'N' ) where S is what type of car it is and N is new or bool value to determine if the car is new or not.
This third function would then switch on the parameters
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
void calcCost( char carType, bool isNew )
{
if ( isNew )
{
switch ( carType )
{
case 's':
case 'S':
cout << "A new SUV will cost...\n";
//... //other types of cars
}
}
else
{
switch ( carType )
{
case 's':
case 'S':
cout << "An old SUV will cost...\n";
//... //other types of cars
}
}
}
|
Something like that would be an alternative... Let me know if that is more difficult to follow.
Also, try to get away from using system("anything"); in your programs. This is depenant on the OS you are using (not portable), and is actually quite resource intensive (calls that involve OS level functionality to operate usually are). There are many more reasons why not to do this, Duoas made a good post about this in another thread if you want to search.
Instead, try using getchar(); to tell your program to wait for another character to be sent to the input stream.