UMBC CMSC 104 CSEE | 104 | current 104

CMSC104, Fall 2005

Programming Project 3

How Cold is It?!?

Out: Wednesday, November 18, 2005
Due Date: Thursday, December 1, 2005 before 11:59PM


The Objective

This project is designed to give you practice working with functions. It will also give you more practice working with loops.

Helpful Tools

http://www.onlineconversion.com/ has converters that  convert Celsius->Fahrenheit & Fahrenheit->Celsius and MPH->KPH
Also to verify your final answer for windchill you can look at the table below. 
Note: if your program is not using functions you will loose points!
Recommendations 
1) use do_while loop to do the repetitive work of  of asking for 
the values and other computations (look at lecture L14 slides 12 and 13) 
2) make output of your program look like the sample output (as much as possible!!!)
3) follow the  Indentation Styles and C Coding Standards.

The Background

With winter right around the corner, cold weather is on its way. Everyone knows that when the weatherperson says the temperature is 35 degrees, you might walk outside to find it feels like it is only 10 degrees or maybe even lower. It all depends on the wind! The wind causes it to feel a lot colder than it actually is. You have decided to prepare yourself for Winter by creating software that can give an approximate windchill temperature. As long as you know the temperature and the wind speed outside (current weather conditions), you can calculate the approximate windchill temperature. Before you leave the house, you can be sure that you are dressed appropriately!

The Task

Your job is to write a program that will accept as input the temperature and the wind speed and will output the windchill temperature. You should use the following formula to calculate the windchill temperature:

W = 13.12 + 0.6215 * t - 11.37 * v 0.16 + 0.3965 * t * v 0.16

where

   v = wind speed in km/hr

   t = temperature in degrees Celsius

   W = windchill temperature (in degrees Celsius)

Wait a minute! The formula given for windchill temperature expects the temperature in Celsius and the wind speed in kilometers per hour. Since we are used to thinking in terms of Fahrenheit and miles per hour, this presents a slight problem. Your solution is to convert the input from the user into its appropriate form before calculating the windchill temperature. You will accept the temperature in degrees Fahrenheit and covert it to degrees Celsius. You will accept the wind speed in miles per hour and convert it to kilometers per hour. Since this project involves functions, you will write the functions needed to do the conversions mentioned above.

For this project, since it is your first using functions, I am providing you with the function prototypes needed. You must use the following function prototypes EXACTLY. You may not change them in any way. However, you may use additional functions if you wish.

  • void PrintGreeting (void); - This function prints an explanation of the program to the user. You should assume the user knows nothing about the program and give a detailed explanation.

  • float FindWindChillTemperature (float degrees, float windSpeed); - This function calculates the windchill temperature. It takes the degrees in Celsius and the wind speed in kilometers/hour as arguments. It returns the windchill temperature in degrees Celsius.

  • float CelsiusToFahrenheit (float celsius); - This function converts a temperature from Celsius to Fahrenheit. It takes the Celsius temperature to be converted as an argument and returns the converted Fahrenheit temperature.

  • float FahrenheitToCelsius (float fahrenheit); - This function converts a temperature from Fahrenheit to Celsius. It takes the Fahrenheit temperature to be converted as an argument and returns the converted Celsius temperature.

  • float MilesToKilometers (float miles); - This function converts a number from miles per hour to kilometers per hour. It takes the miles to be converted as an argument and returns the converted number of kilometers.

  • float GetPositiveValueOfSpeed (void); - This function scans in a value from the user and checks to make sure it is greater than 0. It should only prompt the user if the value entered is equal to or below 0. It is meant to be a general function (module) that can be reused in other programs. Therefore, it should not have a specific prompt. You should prompt the user to enter the wind speed in main(). Then, inside of the function, you should scan the number in and do error checking.

  • float GetTemperature(void); - This function prompts the user to enter a temperature and scans in the temperature. It should check to make sure the temperature is less than or equal to 50. If the number is greater than 50, it should print an appropriate error message and allow the user to enter another number. It is not meant to be a general function. It is a very specific function written only for this program.

  • void PrintResults (float windChill); - This function displays the final results to the user. It should display the windchill. It should also print an appropriate message to the user according to the scale below. I have included sample messages but you can create your own messages if you'd like. You should not change the temperature ranges given, only the messages that print.

     

    Temperature Range Warning Message
    temp >= 20 "Don't forget your coat!"
    temp < 20 but > 0 "Don't forget your hat, scarf & gloves!"
    temp <= 0 "Don't even bother going out!"

 

More Details

  • Your program should continue prompting the user for another temperature until the user enters 'n' for quit. The user should type 'y' to enter another temperature.

  • You should use the following symbolic constants:
    #define KILOMETERS_PER_MILE  1.61
    #define MAX_TEMPERATURE      50
    	
  • As mentioned above, before using the windchill formula, you must convert the user input into the appropriate form. Keep in mind, that the windchill formula also returns a value in degrees Celsius. Therefore, it is also necessary to convert the number back to Fahrenheit before printing the results.

  • The windchill temperature formula only works with a temperature of 10 degrees Celsius or less. Therefore, you must restrict the user temperature input to a value of 50 degress Fahrenheit or less (10 degrees Celsius is equal to 50 degress Fahrenheit.)

  • The formula for windchill requires that you raise the windspeed (v) to the 0.16 power. In order to do so, you need to use the pow() function from the math library.

    prototype of power function

    double pow (double x, double y);

    float pow (float x, float y);

    it takes x and razes it to the yth power.

    Remember that in order to use a math library function, you must

    #include <math.h>

    You must also explicitly link to the math libarary. To do so, you should compile with the -lm flag. For example:


    gcc -ansi -Wall proj3.c -lm

Sample Output

linux2[176]% gcc -ansi -Wall proj3.c  -lm
linux2[177]% a.out

[Your greeting goes here.]

Please enter a temperature (in degrees Fahrenheit): 35
Please enter the wind speed (in mph): 35

*******************************************************
*    Brrr! The windchill temperature is  21 F   --    *
*           Don't forget your coat!!                  *
*******************************************************


Would you like to enter another temperature (y or n)? y
Please enter a temperature (in degrees Fahrenheit): 30
Please enter the wind speed (in mph): 35

*******************************************************
*    Brrr! The windchill temperature is  14 F   --    *
*          Don't forget your hat, scarf & gloves!!    *
*******************************************************


Would you like to enter another temperature (y or n)? y
Please enter a temperature (in degrees Fahrenheit): 10
Please enter the wind speed (in mph): 35

*******************************************************
*    Brrr! The windchill temperature is -14 F   --    *
*          Don't even bother going out!!              *
*******************************************************


Would you like to enter another temperature (y or n)? y
Please enter a temperature (in degrees Fahrenheit): 60
The temperature must be less than or equal to 50.
Please enter a new temperature: 65
The temperature must be less than or equal to 50.
Please enter a new temperature: 30
Please enter the wind speed (in mph): -4
The number must be greater than 0.   
Please enter another number: -10
The number must be greater than 0.   
Please enter another number: 40


*******************************************************
*    Brrr! The windchill temperature is  13 F   --    *
*          Don't forget your hat, scarf & gloves!!    *
*******************************************************


Would you like to enter another temperature (y or n)? n

Stay warm!!

linux2[178]%

Submitting the Program

Your program should be in a file called proj3.c and comply with one of the Indentation Styles and C Coding Standards.

Here is a sample submission command. Note that the project name starts with uppercase 'P'.

submit cs104_0301 Proj3 proj3.c

To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show the file that you submitted in a format similar to the Unix 'ls' command.

submitls cs104_0301 Proj3