A little thing: Your
exit(1);
statements are BEFORE you print the error messages, which means that the program will close before they actually get printed! Try moving the exit statement to the end of the block.
Why do you have "maxHours"? You don't even use if for anything...
Also, your if statements are a bit wierd. For example, you have:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
if (package == 'A') { // If package 'A' was chosen
if (hours <= 10) // If the number of hours isn't greater than 10
cost = 9.95; // Set the cost to 9.95
// Output the cost.
// Here, the cost will either be 9.95, or some random number
// (maybe 0 based on your compiler). This is because you haven't
// initialized cost yet.
cout << "Your total payment for this month is $" << cost << endl;
} else { // Else, if the package is NOT 'A'
cost = 9.95 + 2.00 * (hours - 10);
cout << "Your total payment for this month is $" << cost << endl;
}
|
See what you did there? You have the cost being calculated for when the chosen package was NOT 'A', so that it would calculate only if package 'B' or 'C' was chosen.
Instead, you may want to do this:
1 2 3 4 5 6 7 8 9 10 11
|
if (package == 'A') {
if (hours <= 10)
cost = 9.95;
else
cost = 9.95 + 2.00 * (hours - 10);
cout << "Your total payment for this month is $" << cost << "." << endl;
}
if (package == 'B') {
// same thing
}
|
You shouldn't be checking for their package choice when finding the best options, because you want to find the actual best choice, so you should work it out for every option.
Also, with your printing out at the end, you have neglected to insert a space between cost and hours, which is why you got
0.0014.