Site hosted by Angelfire.com: Build your free website today!

 

Bonus #10
 

 

 

 

 


Using If, And (&&), Or ( | | )

 

You have taken a job at a year round resort and the manager asks that you would program the resorts electronic sign to display the current temperature and the recommended activity resulting from the current temperature.  The temperature will be entered into the program by the user, and the activities correspond as follows:

 

                        Activity             Temperature

                  --------------------         -------------------------

          Swimming                       temp > 85

                         Tennis                      70 < temp <= 85

                          Golf                         32 < temp <= 70

                         Skiing                        0 < temp <= 32

                        Dancing                        temp <= 0

 

Again, only the temperature will be entered by the user.  Compare the temperature with the different intervals by using if statements.  Nested if / else statements are the best.

 

Ex. 

cout << “The recommended activity is “;

if (temp > 85) cout << “swimming. “;

if (temp <= 85 and temp > 70) cout << “tennis.”;

 

OR ( better yet!)

cout << “The recommended activity is “;

if (temp > 85) cout << “swimming. “;

else if (temp <= 85 and temp > 70) cout << “tennis.”;                          

Life is what happens when you’re busy making other plans.

            ~John Lennon

 

else cout <<”dancing”;

 

Good Luck!!