// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include #include #include #include //need this to use the pow math using namespace std; using std::cout; using std::cin; using std::endl; float far; float cel; float mph; float newFar; float chill; //The following const are for the while loops to control what user can enter const int celmin = -62; const float celmax = 49.5; const int farmin = -80; const int farmax = 121; const int mphmin = 0; const int mphmax = 231; //to check for user to enter celcius or fahrenheit string check; const string celcheck = "c"; float celtofar(float cel); float getParam(float& far, float& mph); float windchill(float far, float mph); float getMPH(float& mph); int main() // calls functions and then displays the fahrenheit and windchill at the end { far = 0.0; cel = 0.0; mph = 0.0; cout << "Do you want to enter fahrenheit or celcius? Enter f or c" << endl; cin >> check; if (check == celcheck) { celtofar(cel); far = newFar; getMPH(mph); } else getParam(far, mph); windchill(far, mph); cout << "You entered " << far << "F" << endl; cout << "For " << far << " degrees F and " << mph << " MPH wind speed, the windchill is: " << chill; return 0; } float getParam(float& far, float& mph) //gets fahrenheit and wind speed from user { cout << "Please enter your fahrenheit temp:" << endl; cout << "Must be between " << farmin << " and " << farmax << endl; cin >> far; while (far < farmin || far > farmax) { cout << "Please enter your fahrenheit temp:" << endl; cout << "Must be between " << farmin << " and " << farmax << endl; cin >> far; } cout << "Please enter your wind speed in mph:" << endl; cout << "Must be between " << mphmin << " and " << mphmax << endl; cin >> mph; while (mph < mphmin || mph > mphmax) { cout << "Please enter your wind speed in mph:" << endl; cout << "Must be between " << mphmin << " and " << mphmax << endl; cin >> mph; } return far, mph; } float celtofar(float cel) //calculates celcius to fahrenheit and returns the value { cout << "Please enter your celcius temp:" << endl; cout << "Must be between " << celmin << " and " << celmax << endl; cin >> cel; while (cel < celmin || cel > celmax) { cout << "Please enter your celcius temp:" << endl; cout << "Must be between " << celmin << " and " << celmax << endl; cin >> cel; } newFar = (9 / 5) * cel + 32; return newFar; } float windchill(float far, float mph) //calculates wind chill and returns it { chill = 35.74 + (.6215 * far) - (35.75 * pow(mph, .16)) + (.4275 * pow(far, .16)); return chill; } float getMPH(float& mph) //gets mph only for when you select celcius function { cout << "Please enter your wind speed in mph:" << endl; cout << "Must be between " << mphmin << " and " << mphmax << endl; cin >> mph; while (mph < mphmin || mph > mphmax) { cout << "Please enter your wind speed in mph:" << endl; cout << "Must be between " << mphmin << " and " << mphmax << endl; cin >> mph; } return mph; }