aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CST 126/Homework 1/main.cpp147
1 files changed, 145 insertions, 2 deletions
diff --git a/CST 126/Homework 1/main.cpp b/CST 126/Homework 1/main.cpp
index 5d25e6d..cf22bcd 100644
--- a/CST 126/Homework 1/main.cpp
+++ b/CST 126/Homework 1/main.cpp
@@ -1,12 +1,155 @@
// Name: Logan Gillespie
// Class: CST 126
// Date: 3/31/24
-// Assignment: Homework
+// Assignment: Homework 1
#include <iostream>
using namespace std;
+void moneyConverter();
+void guessingGame();
+void temperatureLog();
+
int main()
{
- cout << "Hello World" << endl;
+ int choice = 0;
+ do {
+ cout << "Welcome to my program! Here are your options:" << endl;
+ cout << "0. Quit" << endl;
+ cout << "1. Money Converter" << endl;
+ cout << "2. Guessing Game" << endl;
+ cout << "3. Temperature Log" << endl;
+ cin >> choice;
+ switch (choice) {
+ case 1:
+ moneyConverter();
+ break;
+ case 2:
+ guessingGame();
+ break;
+ case 3:
+ temperatureLog();
+ break;
+ }
+ } while (choice != 0);
+}
+
+void moneyConverter() {
+ float usd = 1.00;
+ float euro = 0.94;
+ float baht = 36.98;
+ float rupee = 298.73;
+ float pound = 0.80;
+ string from;
+ string to;
+ float amount = 0.00;
+ float interim = 0.00;
+ cout << "Options:\nUSD\nEuro\nBaht\nRupee\nPound\n";
+ cout << "Which curency to convert from?\n";
+ cin >> from;
+ cout << "Which curency to convert to?\n";
+ cin >> to;
+ cout << "How much of the starting curency?\n";
+ cin >> amount;
+ if (from == "Euro" || from == "euro") {
+ interim = amount / euro;
+ }
+ else if (from == "Baht" || from == "baht") {
+ interim = amount / baht;
+ }
+ else if (from == "Rupee" || from == "rupee") {
+ interim = amount / rupee;
+ }
+ else if (from == "Pound" || from == "pound") {
+ interim = amount / pound;
+ }
+ else if (from == "USD" || from == "usd") {
+ interim = amount;
+ }
+ if (to == "Euro" || to == "euro") {
+ interim = interim * euro;
+ }
+ else if (to == "Baht" || to == "baht") {
+ interim = interim * baht;
+ }
+ else if (to == "Rupee" || to == "rupee") {
+ interim = interim * rupee;
+ }
+ else if (to == "Pound" || to == "pound") {
+ interim = interim * pound;
+ }
+ cout << amount << " " << from << " converts to " << interim << " " << to << endl;
+}
+
+void guessingGame() {
+ srand(time(NULL));
+ int guess = 0;
+ int tries = 0;
+ int target = rand() % 10001;
+ while (guess != target && tries < 20) {
+ cout << "Enter your guess" << endl;
+ cin >> guess;
+ if (guess < target) {
+ cout << "The number is higher." << endl;
+ }
+ else if (guess > target) {
+ cout << "The number is lower." << endl;
+ }
+ tries = tries + 1;
+ }
+ if (tries < 20) {
+ cout << "Congrats! No one remembers the losers" << endl;
+ }
+ if (tries == 20) {
+ cout << "Too Bad! All your base are belong to us" << endl;
+ }
+}
+
+void temperatureLog() {
+ struct Temperature {
+ float high;
+ float low;
+ };
+
+ Temperature weeklyLog[7];
+
+ for (int i = 0; i < 7; ++i) {
+ cout << "Day " << i + 1 << ":\n";
+ cout << "Enter high temperature: ";
+ cin >> weeklyLog[i].high;
+ cout << "Enter low temperature: ";
+ cin >> weeklyLog[i].low;
+ }
+
+ float totalHigh = 0, totalLow = 0;
+ for (int i = 0; i < 7; ++i) {
+ totalHigh += weeklyLog[i].high;
+ totalLow += weeklyLog[i].low;
+ }
+ float averageHigh = totalHigh / 7;
+ float averageLow = totalLow / 7;
+
+ float largestDifference = 0;
+ for (int i = 0; i < 7; ++i) {
+ float difference = weeklyLog[i].high - weeklyLog[i].low;
+ if (difference > largestDifference) {
+ largestDifference = difference;
+ }
+ }
+ float lowestTemp = weeklyLog[0].low;
+ float highestTemp = weeklyLog[0].high;
+ for (int i = 1; i < 7; ++i) {
+ if (weeklyLog[i].low < lowestTemp) {
+ lowestTemp = weeklyLog[i].low;
+ }
+ if (weeklyLog[i].high > highestTemp) {
+ highestTemp = weeklyLog[i].high;
+ }
+ }
+
+ cout << "\nAverage high temperature for the week: " << averageHigh << endl;
+ cout << "Average low temperature for the week: " << averageLow << endl;
+ cout << "Largest difference in a day's high/low: " << largestDifference << endl;
+ cout << "Lowest temperature of the week: " << lowestTemp << endl;
+ cout << "Highest temperature of the week: " << highestTemp << endl;
} \ No newline at end of file