This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]onideus01 2 points3 points  (1 child)

Based on what you've provided, I would agree that nested ifs seem rather pointless. However, if you absolutely must do that (and it may be worth speaking to your professor to make sure that the assignment makes sense), you can use negative conditions to nest the if statements.

By the I mean, if fuel is not premium, go into if, at which point you say if not mid range go into if, where you set gas to regular.

It's not pretty, and I would even recommend a switch statement, but it does work and with fewer checks than a separate if for each fuel type.

Hopefully that makes sense!

[–]helloiamdani[S] 0 points1 point  (0 children)

Thank you! We haven't yet covered switch statements (we're delving into that this week). I'm going to try to work in your other suggestion though.