summaryrefslogtreecommitdiff
path: root/projects/1/GoodDocsF2.cpp
blob: cde052bc2833c5af9ad781b3b3bb55b142e8696d (plain)
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
#include <iostream>
using namespace std;

/*
1. F to C
  > What is the input temperature? 32
  > What are the units of the input temperature (C for Celcius or F for Fahrenheit)? F
  > Your input temperature is 32F which is 0C.

2. C to F
  > What is the input temperature? 100
  > What are the units of the input temperature (C for Celcius or F for Fahrenheit)? C
  > Your input temperature is 100C which is 212F.

3. Out of range C
  > What is the input temperature? -274
  > What are the units of the input temperature (C for Celcius or F for Fahrenheit)? C
  > Your input temperature is -274C which is out of range (less than -273.15C or -416F)

4. Out of range F
  > What is the input temperature? -417
  > What are the units of the input temperature (C for Celcius or F for Fahrenheit)? F
  > Your input temperature is -417 which is out of range (less than -273.15C or -416F)

5. Unknown unit
  > What is the input temperature? -40
  > What are the units of the input temperature (C for Celcius or F for Fahrenheit)? Q
  > The units you have specified are not one of C (Celcius) or F (Fahrenheit).
*/

int main(void) {
  char input_units, output_units;
  float input_temp, output_temp;
  int error = 0;

  cout << "What is the input temperature? ";
  cin >> input_temp;

  cout << "What are the units of the input temperature (C for Celcius or F for "
          "Fahrenheit)? ";
  cin >> input_units;

  input_units = toupper(input_units);
  if (input_units == 'C') {
    cout << "Your input temperature is " << input_temp << input_units;

    if (input_temp < -273) {
      cout << " which is out of range (less than -273C or -416F)." << endl;
    } else {
      // output_units = 'F';
      output_temp = (input_temp * (9.0 / 5.0)) + 32.0;

      cout << " which is " << output_temp << "F" << "." << endl;
    }
  } else if (input_units == 'F') {
    cout << "Your input temperature is " << input_temp << input_units;

    if (input_temp < -416) {
      cout << " which is out of range (less than -273C or -416F)." << endl;
    } else {
      // output_units = 'C';
      output_temp = (((input_temp - 32.0) * 5.0) / 9.0);

      cout << " which is " << output_temp << "C" << "." << endl;
    }
  } else {
    cout << "The units you have specified are not one of C (Celcius) or F "
            "(Fahrenheit)"
         << endl;
  }
  return 0;
}