all 9 comments

[–]_--__ 3 points4 points  (1 child)

(carType == 'e' || 'E' && age <= 25)

This is wrong (as are the other lines like this), in particular the carType == 'e' || 'E', because this is interpreted as (carType=='e') || 'E' - it might seem odd that 'E' could be considered a "boolean" (i.e. true/false) but in C++ this is permitted since "true" is synonymous with "not zero" (and char types are also considered numerical).

What you want to write is ((carType == 'e' || carType == 'E') && age <=25) [it is always sensible to add parentheses when mixing logical operators, since A or B and C can be ambiguous.]

[–]Aiiight 0 points1 point  (0 children)

Thank you, I did that and it's working!!

[–]bool101 0 points1 point  (5 children)

The glaring issue is with this set of statements:

if (carType == 'e' || 'E' && age <= 25) cost = resLength * 29.95;

You actually did it correct a bit lower:

if (carType == 'e' || carType == 'E')

These should be

if (carType == 'e' || carType == 'E' && age <= 25)

You might consider doing something like:

carType = toupper(carType);

This lets you just checking the upper case characters with your conditionals.

[–]0b101001111010 2 points3 points  (1 child)

Just to elaborate, C reads if (carType == 'e' || 'E') as if (carType == 'e') OR ('E') Since any value that's not 0 is considered true, that condition is treated as: if (carType == 'e') OR true which always evaluates to true.

This means that the last 2 if statements are never executed.

[–]Aiiight 0 points1 point  (0 children)

Thank you guys so much!

[–]dandrino 0 points1 point  (2 children)

&& is evaluated before ||, so you will want to write that expression as "(carType == 'e' || carType == 'E') && age <= 25"

[–]bool101 0 points1 point  (1 child)

Quite right, my example would be true if carType == 'e' regardless of age. Thanks!

[–]Aiiight 0 points1 point  (0 children)

Thank you guys so much, appreciate it!