summaryrefslogtreecommitdiff
path: root/CST116-Lab2-Davis.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CST116-Lab2-Davis.cpp')
-rw-r--r--CST116-Lab2-Davis.cpp163
1 files changed, 163 insertions, 0 deletions
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 <iostream>
+
+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"<<endl;
+ cin >> choice;
+ if (choice == 1) //finding if the user wants C or F
+ {
+ cout << "What is the temperature? Please enter a value between "<<CMIN<<" and "<<CMAX<<endl;
+ cin >> temperature; //getting temp off of C
+ if (temperature < CMIN)
+ {
+ cout <<"Please enter a larger number"<<endl;
+ cin >> temperature;
+ }
+ else if (temperature >CMAX)
+ {
+ cout << "Please enter a smaller number"<<endl;
+ cin >> temperature;
+ }
+ else
+ {
+ temperature = ((9/5) * temperature + 32);
+ }
+ }
+ else if (choice == 2)
+ {
+ cout << "What is the temperature? Please enter a value between "<<FMIN<<" and "<<FMAX<<endl;
+ cin >> temperature; //getting temp off of F
+ if (temperature < FMIN)
+ {
+ cout <<"Please enter a larger number"<<endl;
+ cin >> temperature;
+ }
+ else if (temperature > FMAX)
+ {
+ cout << "Please enter a smaller number"<<endl;
+ cin >> temperature;
+ }
+ else
+ {
+ cout << "Perfect!"<<endl;
+ }
+ }
+ else if (choice > 2 || choice < 1)
+ {
+ do
+ {
+ cout << "Please enter 1 or 2"<<endl;
+ cin >> 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 "<<CMIN<<" and "<<CMAX<<endl;
+ cin >> temperature; //getting temp off of C
+ if (temperature < CMIN)
+ {
+ cout <<"Please enter a larger number"<<endl;
+ cin >> temperature;
+ }
+ else if (temperature > CMAX)
+ {
+ cout << "Please enter a smaller number"<<endl;
+ cin >> temperature;
+ }
+ else
+ {
+ temperature = ((9/5) * temperature + 32);
+ }
+ }
+ else if (choice == 2)
+ {
+ cout << "What is the temperature? Please enter a value between "<<FMIN<<" and "<<FMAX<<endl;
+ cin >> temperature; //getting temp off of F
+ if (temperature < FMIN)
+ {
+ cout <<"Please enter a larger number"<<endl;
+ cin >> temperature;
+ }
+ else if (temperature > FMAX)
+ {
+ cout << "Please enter a smaller number"<<endl;
+ cin >> temperature;
+ }
+ else
+ {
+ cout << "Perfect!"<<endl;
+ }
+ }
+ }
+ else
+ {
+ cout << "uhhhh something went wrong"<<endl;
+ }
+ cout << "Now what is the windspeed in MPH? Please enter a value less than 231 and greater than 0"<<endl; //finding windspeed
+ cin >> windspeed;
+ if (windspeed > 231)
+ {
+ cout << "Please enter a smaller value"<<endl;
+ cin >> windspeed;
+ }
+ else if (windspeed < 0)
+ {
+ cout <<"please enter a larger number"<<endl;
+ cin >> 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 "<<temperature<<endl;
+//print celcius choice in fahrenheit
+ }
+ else if (choice == 2)
+ {
+ cout << "You chose to input your temperature in Fahrenheit. You input "<<temperature<<endl;
+ // prints fahrenheit input
+ }
+ else
+ {
+ cout << "Something went wrong..."<<endl;
+ }
+ cout << endl;
+ cout << "You put "<<windspeed<<" for your windspeed"<<endl; //prints windspeed
+ cout << endl;
+ cout << "Based off your temperature and windspeed, the windchill is "<<windchill<<endl;
+}