mardi 7 juin 2016

Scanning multiple inputs and outputting based on the amount true/false

I have an assignment that is supposed to ask the user a few questions about temperature in regards to a plane launch.

EX:

  • What is the average temperature?
  • Lowest temperature in the past day?
  • Is it raining?

Now the program is suppose to take the input and base it on a few conditions

  • temperature must be 42 degrees
  • temperature couldn't have dropped below 32
  • Can't be raining

So I got the output that gives 'the okay' for the plane launch by nesting some 'if statements', that's all good. The problem is that, depending on the number of incorrect statements, it'll output something different.

EX:

If the only issue is that the temperature is below 32 degrees, it'll output:

"The plane is not launching because the temperature has dropped below 32 degrees in the past day"

If the temperature dropped below 32 degrees AND it's raining, the program will spit out

"The plane is not launching because:

The temperature is below 32 degrees

it's raining"

I know that I can make a whole bunch of if statements for each situation but that'll just make my code massive and confusing. Surely there must be a simpler way to set it up in which 'there are 2 statements false, so print this depending on which 2'. Should I make a switch statement?

The last class I took I separated all of the work into functions and then just called down each one into the main when needed. In this course, we have to do all of the work in the main function and it is kinda confusing because I began learning a different way.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire