aboutsummaryrefslogtreecommitdiff
path: root/CST 126/Homework 1/main.cpp
blob: 18c92254846c95e58f47c12e3334ecfe271447d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Name: Logan Gillespie
// Class: CST 126
// Date: 3/31/24
// Assignment: Homework 1

#include <iostream>
#include <string>
using namespace std;

void moneyConverter();
void guessingGame();
void temperatureLog();

int main()
{
    int choice = 0;
    do {
        cout << "Welcome to our 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;
}