-
Notifications
You must be signed in to change notification settings - Fork 0
/
TempAtDepth.cpp
61 lines (49 loc) · 1.35 KB
/
TempAtDepth.cpp
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
//Fort Hays State University - CSCI 121
//Project 4 - "The Temperature of Earth at a Depth"
//Author: Lindsey Jimenez
//Date: 09-29-2021
#include <iostream>
#include <cmath>
using namespace std;
void print_introduction();
double celsius_at_depth(double depth);
double fahrenheit_at_depth(double celsius);
void print_conclusion(double depth);
//the order of execution
int main()
{
double depth;
char choice;
print_introduction();
do
{
cout << "Enter a depth in KM: ";
cin >> depth;
print_conclusion(depth);
cin >> choice;
} while (choice == 'Y' || choice == 'y');
cout << "Program ended with exit code: 0\n";
return 0;
}
void print_introduction()
{
cout << "Hello! The program will tell you the temperature of the earth at any depth.\n";
}
//calculates temperature in celsius
double celsius_at_depth(double depth)
{
return (10 * depth + 20);
}
//calculates temperature in fahrenheit
double fahrenheit_at_depth(double celsius)
{
return (1.8 * celsius + 32);
}
void print_conclusion(double depth)
{
double celsius = celsius_at_depth(depth);
double fahrenheit = fahrenheit_at_depth(celsius);
cout << "The temperature of the earth at a depth of " << depth << " KM is " << celsius << " in Celsius, and "
<< fahrenheit << " in Fahrenheit.\n";
cout << "Would you like to do it again? (Y/N): ";
}