1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
*/
#include <iostream>
#include <math.h>// allows math fuctions such as pow() to be used
#include <string>
using namespace std;
//prototypes
double AskForTempurature();
double AskForWindSpeed();
int ValidateTempWS(double temp, double windsp);
double CalcWindchill(double temp, double windsp);
int DetermineFrostbiteTimes(double temp, double windsp);
//main fuction
int main()
{
string again; // do loop variable
do // start of loop, runs again if user chooses to
{
double currentTemp;
currentTemp = AskForTempurature();// calls function AskForTemp... and assigns user input into currentTemp
double windGust;
windGust = AskForWindSpeed();// calls function and assigns user input into the variable
int validOrNot = ValidateTempWS(currentTemp, windGust); // runs fuction and determines if values entered are valid (within range)
cout << "When the outside temperature is " << currentTemp;
cout << " degrees F and the wind is blowing " << windGust;
cout << " MPH it feels like ";
double windChill = CalcWindchill(currentTemp, windGust);
double frostbite = DetermineFrostbiteTimes(currentTemp, windGust);
cout << " and you have about " << frostbite;
cout << " minutes until you get frostbite ";
cout << "\nWould you like to do another calculation? (Yes/No)";
getline(cin, again);
if (again == "No") //ends program.
{
cout << "Good Bye. " << endl;
}
} while (again == "Yes");// starts program at the beginning asking for input.
return 0; //return okay
}
//FUNCTIONS
double AskForTempurature() //simple function asking for user to input temp
{
double temperature;
cout << "What is the current Tempurature? \n";
cin >> temperature;
cin.ignore();
return temperature;//returns okay
}
double AskForWindSpeed()
{
double windSpeed;
cout << "What is the current speed the wind is blowing at? (in MPH, only number required) \n"; // simple function asking for speed of wind
cin >> windSpeed;
cin.ignore();
return windSpeed;//returns okay
}
int ValidateTempWS(double temp, double windsp)// validates that temp and wind speed are within range
{
int valid = 0; // variable assigned for return, returns one of the below 'if' or 'else if' statements. // may need to change to 'for loop'
if (temp < 41 && temp > -46)
{
if (windsp < 61 && windsp > 4)
{
cout << "0: ALL OK! \n";
}
}
else if (temp >= 41 || temp <= -46)
{
if (windsp >= 61 || windsp <= 4)
{
cout << "2: BOTH INVALID! \n";
}
}
else if (temp >= 41 || temp <= -46)
{
cout << "3: Temp invalid \n";
}
else if (windsp >= 61 || windsp <= 4)
{
cout << "4: Wind speed invalid \n";
}
return valid;// return okay, does what it's suppose to, may need to change to 'for loop'...
}
double CalcWindchill(double temp, double windsp) // calculates what the temp feels like depending on thermomitor temp and wind speed
{
// T = temp, V = windsp
double first;
first = 35.74 + 0.6215 * temp;
double second;
second = 35.75 * pow(windsp, 0.16);
double third;
third = 0.4275 * temp * pow(windsp, 0.16);
double solution;
solution = first - second + third; //35.74 + 0.6215*T -35.75*(V ^ 0.16) + 0.4275*T*(V ^ 0.16);
cout << solution;
return solution;// formula correct. returns okay
}
int DetermineFrostbiteTimes(double temp, double windsp) // calculates time until receiving frostbite.
{
// T = temp, V = windsp
double first;
first = -24.5 * (0.667 * (windsp * 8/5 + 4.8)) + 2111;
double second;
second = -4.8 - (temp - 32) * 5 / 9;
double third;
third = pow(second, -1.668);
double solution;
solution = first * third; //((-24.5 * ((0.667 * (V * 8/5)) + 4.8)) + 2111) * (-4.8 - ((T - 32) * 5/9))^ -1.668
return solution; // formula correct. returns okay
}
|