forked from riyaaa04/cpp20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.cpp
29 lines (25 loc) · 909 Bytes
/
11.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
#include <iostream>
using namespace std;
int main() {
// Declare variables
float temperature, converted_temperature;
char conversion_direction;
// Prompt the user to enter the temperature and conversion direction
cout << "Enter the temperature to convert: ";
cin >> temperature;
cout << "Enter the conversion direction (C to F or F to C): ";
cin >> conversion_direction;
// Convert the temperature based on the conversion direction|
//(temperature - 32.0) * 5.0 / 9.0;
if (conversion_direction == 'C') {
converted_temperature = (temperature * 9.0) / 5.0 + 32.0;
} else if (conversion_direction == 'F') {
converted_temperature = (temperature - 32.0) * 5.0 / 9.0;
} else {
cout << "Invalid conversion direction." << endl;
return 0;
}
// Print the converted temperature
cout << "The converted temperature is: " << converted_temperature << endl;
return 0;
}