diff options
| author | jacobdw22 <[email protected]> | 2022-11-05 17:09:01 -0700 |
|---|---|---|
| committer | jacobdw22 <[email protected]> | 2022-11-05 17:09:01 -0700 |
| commit | 299e7fbb0e05058820ee1e15922c972b1b4d742f (patch) | |
| tree | 96bd22950e04a451bdf78499a2c6946973cdd028 | |
| parent | Run Results file completed (diff) | |
| download | cst116-lab2-jacobdw22-299e7fbb0e05058820ee1e15922c972b1b4d742f.tar.xz cst116-lab2-jacobdw22-299e7fbb0e05058820ee1e15922c972b1b4d742f.zip | |
Final changes to main code. Just need pseudo code
| -rw-r--r-- | BlankConsoleLab/cst116-lab2-wilson.cpp | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/BlankConsoleLab/cst116-lab2-wilson.cpp b/BlankConsoleLab/cst116-lab2-wilson.cpp index c957e32..2a8a4a7 100644 --- a/BlankConsoleLab/cst116-lab2-wilson.cpp +++ b/BlankConsoleLab/cst116-lab2-wilson.cpp @@ -1,92 +1,92 @@ // BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there. -// +// Jacob Wilson, cst116, Lab2, 11-5-2022 -#include <iostream> -#include <iomanip> -#include <stdio.h> /* printf */ -#include <math.h> /* pow */ -#include <cmath> /* pow */ +#include <iostream> // cout, cin, endl +#include <iomanip> +#include <stdio.h> // printf +#include <math.h> // pow +#include <cmath> // pow -using namespace std; +using namespace std; //Allows for std to not be needed for every std:: item -using std::cout; -using std::cin; -using std::endl; +using std::cout; //Prints to window +using std::cin; //Reads from user +using std::endl; //Ends current line const float FMAX = 121; const float FMIN = -80; const float CMAX = 49.5; -const float CMIN = -62; //Set values for minimum and maximum temperatures. +const float CMIN = -62; //Set values for minimum and maximum temperatures, both Fahrenheit and Celsius. -float CtoF(float Fahrenheit, float Celsius) { //float function so that it returns a float +float CtoF(float Fahrenheit, float Celsius) { //float function so that it returns a float for Fahrenheit (more precise) - Fahrenheit = (Celsius * 9.0 / 5.0) + 32.0; //Converts Celsius to Fahrenheit + Fahrenheit = (Celsius * 9.0 / 5.0) + 32.0; //Converts Celsius to Fahrenheit - return Fahrenheit; //Returns the newly defined fahrenheit to main + return Fahrenheit; //Returns the newly defined fahrenheit to main } -float WindSpeedFinder(float* windspeed) { //Float function to return float value +float WindSpeedFinder(float* windspeed) { //Float function to return float value -Loop2: +Loop2: //Placeholder to loop back to - cout << "Please enter the wind speed between 0 and 231 mph: "; - cin >> *windspeed; + cout << "Please enter the wind speed between 0 and 231 mph: "; //Prompts user to enter a wind speed + cin >> *windspeed; //Reads in windspeed from user if (*windspeed <= 231 && *windspeed >= 0) { cout << "\n\tThe windspeed is " << *windspeed << " mph." << endl; - return *windspeed; + return *windspeed; //If the windspeed is between the min and max provided, windspeed will be returned } else { - goto Loop2; //Goes back to placeholder to Loop in case of invalid response (past limits) + goto Loop2; //Goes back to placeholder to Loop in case of invalid response (past limits) } } -/*float WindChill(float Fahrenheit, float* windspeed) { +float WindChill(float TEMP, float SPEED, float Chill) { //Converts wind speed and Fahrenheit to wind chill - double Chill = 35.74 + 0.6215 * Fahrenheit - 35.75 * (pow(*windspeed, 0.16)) + 0.4275 * Fahrenheit * (pow(*windspeed, 0.16)); + float x = 0.16; //placeholder value for equation (faster) + + Chill = 35.74 + (0.6215 * TEMP) - (35.75 * (pow(SPEED, x))) + (0.4275 * TEMP * (pow(SPEED, x))); //equation to convert to wind chill - return Chill; + return Chill; //returns Chill to main -}*/ +} -int main() +int main() //Main function { - float Celsius = 0.0; //Defines Celsius for the conversion function - float Fahrenheit = 0.0; //Defines Fahrenheit for the conversion function - float windspeed = 0.0; //Defines windspeed + float Celsius = 0.0; //Defines Celsius for the conversion function + float Fahrenheit = 0.0; //Defines Fahrenheit for the conversion function + float windspeed = 0.0; //Defines windspeed + float Chill = 0.0; //Defines Chill - Loop: //Placeholder to loop back to + Loop: //Placeholder to loop back to - cout << "Please enter a temperature between -62 and 49.5 degrees Celsius: "; - cin >> Celsius; //Reads in Celsius from the user input + cout << "Please enter a temperature between -62 and 49.5 degrees Celsius: "; //Prompts user to enter a temperature in Celsius + cin >> Celsius; //Reads in Celsius from the user input if (Celsius <= CMAX && Celsius >= CMIN) { - cout << "\t" << Celsius << " Degrees Celsius is approximately " << CtoF(Fahrenheit, Celsius) << " Degrees Fahrenheit\n\n"; + cout << "\t" << Celsius << " Degrees Celsius is approximately " << CtoF(Fahrenheit, Celsius) << " Degrees Fahrenheit\n\n"; + //if the value of Celsius is between the limits, the celsius to fahrenheit function will be run and returned, then printed } else { - goto Loop; //Goes back to placeholder to Loop in case of invalid response (past limits) + goto Loop; //Goes back to placeholder to Loop in case of invalid response (past limits) } - WindSpeedFinder(&windspeed); - - - //cout << "\n\tThe windchill is: " << WindChill(Fahrenheit, &windspeed) << endl; - - float x = 0.16; + float TEMP = CtoF(Fahrenheit, Celsius); //Re-defines the value returned from celsius to fahrenheit function + float SPEED = WindSpeedFinder(&windspeed); //Re-defines the value returned from the wind speed finder function - float Chill = 35.74 + (0.6215 * CtoF(Fahrenheit, Celsius)) - (35.75 * (pow(windspeed, x))) + (0.4275 * CtoF(Fahrenheit, Celsius) * (pow(windspeed, x))); + float CHILL = WindChill(TEMP, SPEED, Chill); //Re-defines the value returned from the wind chill function - cout << "\tThe wind chill is: " << Chill << endl; + cout << "\tThe wind chill is: " << CHILL << endl; //Prints the windchill } |