bool minute ;
You are comparing minute against numbers. A bool can only be true or false. Change minute to be an int or a double.
_________________________________
In adding that && to your if statement, you changed the logic flow of your code.
If your plan is anything but A/a, and you have less than 450 minutes, you will enter the else if statement. If you chose plan == 'C' and minute == 500, you would reach your else statement.
Make sure you are able to describe to yourself the plan in words first instead of code, and then try to translate the words into code, thinking about what each possible choice/outcome will be.
It's okay to have ifs within ifs when necessary, I didn't mean to imply that part of your structure was wrong. I was referring to your lines 40, 53, and 65 when saying "if, else if" structure would be preferred there (A switch would be the best to use here, but you said you didn't want that).
____________________
You also have a lot of code that's difficult to maintain. You define PlanA and PlanB as some numbers, but then don't initialize PlanC. You define PlanA and PlanB as 39.99 and 59.99, but then you use the raw numbers (lines 49 and 61 in your OP). This is commonly known as a "magic number" in programming, and I'd suggest you replace it with a named variable. It also makes it more maintainable because you only need to change one number instead of a bunch of instances of the same number.
https://en.wikipedia.org/wiki/Magic_number_(programming)#Unnamed_numerical_constants
You also have a lot of repetition of code, such as on lines 49 and 50, and 61 and 62. It would be useful to factor this into a function and pass in which plan you want, but if this is above what you've learned so far, don't worry about that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
PlanC = 69.99;
const int PlanA_minutes = 450;
const int PlanB_minutes = 900;
totalBill = 0.00; // default if not on a plan
if (plan == 'A' || plan == 'a')
{
if (minute <= PlanA_minutes )
{
totalBill = PlanA;
}
else // "else if" is not necessary here since there's only 1 other possibility
{
totalBill = ( PlanA + .45 * ( minute - PlanA_minutes ) );
}
}
else if (plan == 'B' || plan == 'b')
{
if (minute <= PlanB_minutes )
{
totalBill = PlanB;
}
else
{
totalBill = ( PlanB + .45 * ( minute - PlanB_minutes ) ); // changed from minute - 450, not sure if this was intended
}
}
else if ( plan == 'C' || plan == 'c' )
{
totalBill = PlanC;
}
cout << "Bill amount is $ " << totalBill << endl;
|
That would be how I would personally format it.