blob: 5b2941c79c0aef9d5eeffcd2cb5a4908171bf9cf (
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
|
// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
/*
* Benjamin Smith
* CST116 Lab 2
*/
#include <iostream>
using namespace std;
const float temp_min_F = -80, temp_max_F = 121, temp_min_C = -61, temp_max_C = 49.5, wind_min = 0, wind_max = 231;
string input = "";
float temperature = 0, wind_speed = 0;
int main()
{
//Temperature type input
cout << "Before you input a temperature value, you must first determine if it's in fahrenheit or celsius." << endl;
cout << "Please input 'F' for fahrenheit or 'C' for celsius: ";
cin >> input;
while (input != "F" && input != "C") {
cout << "That input is invalid." << endl;
cout << "Make sure your input is capitalized." << endl;
cout << "Please input 'F' for fahrenheit or 'C' for celsius: ";
cin >> input;
}
//Temperature value input
if (input == "C")
cout << endl << endl << "Now please input a temperature between the range " << temp_min_C << " to " << temp_min_C << ": ";
if (input == "F")
cout << endl << endl << "Now please input a temperature between the range " << temp_min_F << " to " << temp_max_F << ": ";
cin >> temperature;
if (input == "C") {
while (temperature < -62 || temperature > 49.5) {
cout << "That input is invalid." << endl << "Your value must be between " << temp_min_C << " and " << temp_min_C << "." << endl;
cout << "Please input the temperature again: ";
cin >> temperature;
}
}
else {
while (temperature < -80 || temperature > 121) {
cout << "That input is invalid." << endl << "Your value must be between " << temp_min_C << " and " << temp_min_C << "." << endl;
cout << "Please input the temperature again: ";
cin >> temperature;
}
}
//Wind Speed value input
cout << endl << endl << "Now please input a wind speed between the range " << wind_min << " to " << wind_max << ": ";
cin >> wind_speed;
while (wind_speed < 0 || wind_speed > 231) {
cout << "That input is invalid." << endl << "Your value must be between " << wind_min << " and " << wind_max << "." << endl;
cout << "Please input the wind speed again: ";
cin >> wind_speed;
}
//Convert Celsius to Fahrenheit
if (input == "C") {
temperature *= 1.8;
temperature += 32;
}
}
|