Getting Started

Refer to Lab 1 if you need a reminder about how to start Cygwin Terminal or Notepad++.

Start by downloading CS101_Lab06.zip, saving it in the directory H:\CS101.

Start a Cygwin Terminal and run the following commands:

cd h:
cd CS101
unzip CS101_Lab06.zip
cd CS101_Lab06

Using Notepad++, open the file

H:\CS101\CS101_Lab06\WeatherApp.cpp

Your Task

Write a program that provides some feedback on the weather conditions given the current temperature and chance for precipitation.

Your program should prompt the user to enter the current temperature and the chance for precipitation (as a percentage). Based on the temperature, your program should then print one of the following messages:

Additionally, your program should simulate the weather to determine whether or not it rained. To do this, first generate a random number such that there are 100 possible values (e.g., 0 to 99, or 1 to 100). If the generated number is less than the percent chance of precipitation entered by the user, then your program should indicate that it has precipitated. Otherwise, your program should indicate that it has not precipitated.

Example run (user input in bold):

Enter the current temperature: 78
What is the chance of precipitation (in percentage): 85

It's a warm day.
It's raining, better bring an umbrella.

In the example above, there was an 85 percent chance of precipitation, and it rained.

Another example (user input in bold):

Enter the current temperature: 53
What is the chance of precipitation (in percentage): 76

It's a cool day.
No rain today.

In this second example, there was an 76 percent chance of precipitation, but it did not rain.

A third example (user input in bold):

Enter the current temperature: 25
What is the chance of precipitation (in percentage): 88

It's very cold outside.
It's snowing, put on your boots.

In this example, there was an 88 percent chance of precipitation and because it was so cold, it snowed.

When you are ready to compile the program, in the Cygwin window type the command

make

To run the program, in the Cygwin window type the command

./WeatherApp.exe

Hints

Use an if/else if statement to determine which message to print. Use a second if/else if statement to determine which of the three precipitation messages to print.

It snows when precipitation occurs at temperates less than or equal to 32 degrees.

You should add the following #include directives at the top of the file:

#include <stdlib.h>
#include <time.h>

Near the beginning of the statements in your main function add the statement

srand(time(0));

This statement will seed the random number generator with a value based on the current time.

When the program simulates the weather, it can “randomly” choose an integer with 100 possible values (0 to 99 inclusive) using the expression

rand() % 100

Submit

To submit your work, type the command

make submit

Enter your Marmoset username and password (which you should have received by email.) Note that your password will not be echoed to the screen.