I am supposed to write a program for my class that calculates the windchill given the wind velocity ad temperature. I must use 4 seperate functions (one that displays instructions, reads in instructions, calculates result, and displays result) but I can not get my program to compile. I have been working for hours but I can not figure it out.
#include <iostream>
#include <cmath>
using namespace std;
void instruct() //function that displays instructions
{
cout << "This program calculates wind chill. " << endl;
}
void readIn(double T, double V) //function that reads in variables
{
cout << "Please enter the wind speed. " << endl;
cin >> V;
cout << "Please enter the temperature. " << endl;
cin >> T;
}
Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
That was fun. Based on the suggestions and a couple of things I did the output I get is:
This program calculates wind chill.
Please enter the wind speed.: 10
Please enter the temperature.: 30
The wind chill is 21
Press Enter to continue:
Or
This program calculates wind chill.
Please enter the wind speed.: 10
Please enter the temperature.: 30
The wind chill is 20.978
Press Enter to continue:
My program now works as it should, but now I must only allow the program to run if the temperature is between 0 and 50 degrees and the windspeed must be in between 0 and 100 mph. my code is now
Your display function needs curly braces { } around it.
And you're missing a closing brace on the "else" block (line 32-34).
And your main function does not have a closing brace either, although I assume that was just a copy-paste mishap.
int main()
{
instruct(); //calls for instruct function to run
double temp{}, windSpeed{}, windChill{};
std::cout << std::fixed << std::setprecision(3); // <--- (0) to show whole numbers. 1 or more as you like.
readIn(temp, windSpeed); //calls for readIn function to run
windChill = calcChill(temp, windSpeed); //calls for calcChill function to run
display(windChill, temp, windSpeed); //calls for display function to run
//display(calcChill(temp, windSpeed)); // <--- Could be written as. It would eliminate the variable "windChill" and line 54.
// A fair C++ replacement for "system("pause")". Or a way to pause the program.
// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue: ";
std::cin.get();
return 0; // <--- Not required, but makes a good break point.
}
For my reference I am using the line numbers in my IDE.
For this function there are 3 choices that you can do. I would recommend the last 1, but do what works best for you:
Wind speeds of less than 5 MPH statute have virtually no wind chill
factor on the old formula and less than 3 MPH statute have little
or no effect on the new formula!
I do not know if the 3 is the best choice because I did see a table where the minimum was 5. Either way at some point the wind speed gets low enough to where the wind speed has no effect on the wind chill.
If you are required to use a wind speed of zero than by all means use that.
Other than the corrections that Ganado has mentioned the program works well.
my program works great! Now I just need to make it so that the program will run continuously until the user prompts it to stop. Any suggestions on how I can do this?
void readIn(double& T, double& V)
{
cout << "Please enter the wind speed (0 to exit). " << endl;
cin >> V;
if (V != 0.0) {
cout << "Please enter the temperature. " << endl;
cin >> T;
}
}
...
double T = 0.0, V = 0.0;
do {
readIn(T , V);
if (V != 0.0)
display(calcChill(T , V));
} while (V != 0.0);