summaryrefslogtreecommitdiff
path: root/CST116-Lab2-Davis.cpp
blob: 6ce6be08060c76b950cf496ad4f0dbc61a2f1622 (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
157
158
159
160
161
162
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;
}