aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChanin Timbal <[email protected]>2024-06-03 14:27:08 -0700
committerChanin Timbal <[email protected]>2024-06-03 14:27:08 -0700
commiteb596ef451e9e2ca6d38995c747e762b4a6bd016 (patch)
tree38748a03f7981a9c192b200d92ca0cfdd3a7e5a1
parenttrying to fix! (diff)
downloadhomework-1-chaninnohea-eb596ef451e9e2ca6d38995c747e762b4a6bd016.tar.xz
homework-1-chaninnohea-eb596ef451e9e2ca6d38995c747e762b4a6bd016.zip
Restored completed Homework 1 that was accidentally completed, Code should be final
-rw-r--r--CST 126/Homework 1/header.h84
-rw-r--r--CST 126/Homework 1/main.cpp4
2 files changed, 80 insertions, 8 deletions
diff --git a/CST 126/Homework 1/header.h b/CST 126/Homework 1/header.h
index 929fbca..2c2f002 100644
--- a/CST 126/Homework 1/header.h
+++ b/CST 126/Homework 1/header.h
@@ -11,7 +11,8 @@ void display_options();
float convert(float input, float output, float amount);
void run_conversion(char again);
void currency_menu();
-void guessing_game(char again);
+void guessing_game();
+void temperature_logger();
//Loop to run the conversion while the user wants to
void run_conversion(char again)
@@ -121,7 +122,7 @@ void currency_menu()
}
//guessing game function
-void guessing_game(char again)
+void guessing_game()
{
std::random_device dev;
std::mt19937 rng(dev());
@@ -135,7 +136,7 @@ void guessing_game(char again)
cout << "I have selected a number between 1 and 10000, you have 20 tries to guess it!" << endl;
cout << "" << endl;
- cout << "hint: " << random_number << endl;
+ //cout << "hint: " << random_number << endl;
cout << "Enter your guess: ";
cin >> user_guess;
cin.ignore(100, '\n');
@@ -145,12 +146,14 @@ void guessing_game(char again)
if (user_guess > random_number)
{
cout << "Lower!";
- cout << "Tries left: " << (20 - guess_counter);
+ cout << "Tries left: " << (20 - guess_counter) << endl;
+ cout << "\n";
}
else
{
cout << "Higher!";
- cout << "Tries left: " << (20 - guess_counter);
+ cout << "Tries left: " << (20 - guess_counter) << endl;
+ cout << "\n";
}
guess_counter++;
cout << "Enter your guess: ";
@@ -158,5 +161,74 @@ void guessing_game(char again)
cin.ignore(100, '\n');
}
- cout << "You got it!\n" << endl;
+ if (guess_counter == 20)
+ {
+ cout << "Sorry! You didn't guess it in time. The answer was " << random_number << "\n" << endl;
+ }
+ else
+ cout << "You got it!\n" << endl;
+}
+
+
+void temperature_logger()
+{
+ const int size = 7;
+ struct dailyTemps
+ {
+ float temperature_high;
+ float temperature_low;
+ };
+
+ dailyTemps week[size];
+
+ int day_counter = 1;
+
+
+ for (int i = 0; i < size; i++)
+ {
+ cout << "Enter high temperature for day " << day_counter << ": ";
+ cin >> week[i].temperature_high;
+ cin.ignore(100, '\n');
+ cout << "Enter low temperature for day " << day_counter << ": ";
+ cin >> week[i].temperature_low;
+ cin.ignore(100, '\n');
+ day_counter++;
+ }
+
+
+ float sum_high = 0.0;
+ float sum_low = 0.0;
+ float lowest = week[0].temperature_low;
+ float highest = week[0].temperature_high;
+ float largest_difference = 0.0;
+ float average_temp = 0.0;
+
+ for (int i = 0; i < size; i++)
+ {
+ sum_high += week[i].temperature_high;
+ sum_low += week[i].temperature_low;
+
+ if (week[i].temperature_high > highest)
+ {
+ highest = week[i].temperature_high;
+ }
+
+ if (week[i].temperature_low < lowest)
+ {
+ lowest = week[i].temperature_low;
+ }
+
+ float difference = week[i].temperature_high - week[i].temperature_low;
+ if (difference > largest_difference)
+ {
+ largest_difference = difference;
+ }
+ }
+
+ average_temp = (sum_high/ size + sum_low / size) / 2;
+
+ cout << "\nAverage temperature of the week: " << average_temp << "'F" << endl;
+ cout << "\nLargest Difference in High/Low Temperature in a Day: " << largest_difference << endl;
+ cout << "\nLowest Temperature of the Week: " << lowest << "'F" << endl;
+ cout << "\nHighest Temperature of the Week: " << highest << "'F\n" << endl;
}
diff --git a/CST 126/Homework 1/main.cpp b/CST 126/Homework 1/main.cpp
index 690c255..6f5024f 100644
--- a/CST 126/Homework 1/main.cpp
+++ b/CST 126/Homework 1/main.cpp
@@ -24,12 +24,12 @@ int main()
else if (option == 2)
{
- guessing_game(again);
+ guessing_game();
}
else if (option == 3)
{
-
+ temperature_logger();
}
else
{