From d82e1b71f7d003eead5d5350aaf7da41b142ae15 Mon Sep 17 00:00:00 2001 From: levidavis04 <114828884+levidavis04@users.noreply.github.com> Date: Mon, 14 Nov 2022 15:41:02 -0800 Subject: Add files via upload --- CST116-Lab2-Davis.cpp | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 CST116-Lab2-Davis.cpp (limited to 'CST116-Lab2-Davis.cpp') diff --git a/CST116-Lab2-Davis.cpp b/CST116-Lab2-Davis.cpp new file mode 100644 index 0000000..6ce6be0 --- /dev/null +++ b/CST116-Lab2-Davis.cpp @@ -0,0 +1,163 @@ +// Lab 2; Baby it's cold outside + +#include + +using std::cout; +using std::cin; +using std::endl; + +const int FMIN = -80; +const int FMAX = 121; +const int CMIN = -62; +const float CMAX = 49.5; + +int getdata (int (choice), float (temperature), float (windchill), int (windspeed)); +void printdata(float (temperature), float (windchill), int (windspeed), int (chocie)); + +int main() +{ + float temperature = 0.0; + int choice = 0; + int windspeed = 0; + float windchill = 0.0; + + getdata(int (choice), float (temperature), float (windchill), int (windspeed)); + printdata(float (temperature), float (windchill), int (windspeed), int (choice)); + return 0; +} +int getdata(int (choice), float (temperature), float (windchill), int (windspeed)) +{ + cout <<"Hello!"<< endl; + cout <<"Will you be using Celsius or Fahrenheit? Please enter a '1' for Celsius and '2' for Fahrenheit"<> choice; + if (choice == 1) //finding if the user wants C or F + { + cout << "What is the temperature? Please enter a value between "<> temperature; //getting temp off of C + if (temperature < CMIN) + { + cout <<"Please enter a larger number"<> temperature; + } + else if (temperature >CMAX) + { + cout << "Please enter a smaller number"<> temperature; + } + else + { + temperature = ((9/5) * temperature + 32); + } + } + else if (choice == 2) + { + cout << "What is the temperature? Please enter a value between "<> temperature; //getting temp off of F + if (temperature < FMIN) + { + cout <<"Please enter a larger number"<> temperature; + } + else if (temperature > FMAX) + { + cout << "Please enter a smaller number"<> temperature; + } + else + { + cout << "Perfect!"< 2 || choice < 1) + { + do + { + cout << "Please enter 1 or 2"<> choice; + } + while (choice > 2 || choice < 1); + if (choice == 1) //finding if the user wants C or F + { + cout << "What is the temperature? Please enter a value between "<> temperature; //getting temp off of C + if (temperature < CMIN) + { + cout <<"Please enter a larger number"<> temperature; + } + else if (temperature > CMAX) + { + cout << "Please enter a smaller number"<> temperature; + } + else + { + temperature = ((9/5) * temperature + 32); + } + } + else if (choice == 2) + { + cout << "What is the temperature? Please enter a value between "<> temperature; //getting temp off of F + if (temperature < FMIN) + { + cout <<"Please enter a larger number"<> temperature; + } + else if (temperature > FMAX) + { + cout << "Please enter a smaller number"<> temperature; + } + else + { + cout << "Perfect!"<> windspeed; + if (windspeed > 231) + { + cout << "Please enter a smaller value"<> windspeed; + } + else if (windspeed < 0) + { + cout <<"please enter a larger number"<> windspeed; + } + else + { + windchill = (35.74 + 0.6215 * (temperature) - 35.75 * ((windspeed)^16) + 0.4275 * (temperature) * ((windspeed)^16)); //getting windchill + } + return choice; + return temperature; + return windchill; + return windspeed; +} +void printdata(float (temperature), float (windchill), int (windspeed), int (choice)) +{ + if (choice == 1) + { + cout << "You chose to input your temperature in Celsius. The program has convertered the temp into Fahrenheit and the temperature is "<