3. (简答题)For converting temperature from Celsius to Fahrenheit, or from Fahrenheit to Celsius, we can use the following formulas. -------------------------------------------------- Celsius To Fahrenheit: Fahrenheit = ( Celsius * 9 / 5 ) + 32; Fahrenheit To Celsius: Celsius = ( Fahrenheit - 32 ) * 5 / 9; -------------------------------------------------- Write a program to convert temperature from Fahrenheit to Celsius and vice versa using switch case. In the program, there are three options given to the user. The first choice is to convert the temperature from Celsius to Fahrenheit. The second choice is to convert the temperature from Fahrenheit to Celsius. And the last one is to exit without testing any one of the queries. The program should work as follows: ---------------------------------------------------------- Select Code: For Fahrenheit To Celsius For Celsius To Fahrenheit Enter Your Choice: 1 Enter The Value of Fahrenheit Temperature: 90 Celsius Temperature: 32.2 ---------------------------------------------------------- Select Code: 1. For Fahrenheit To Celsius 2. For Celsius To Fahrenheit Enter Your Choice:2 Enter The Value of Celsius Temperature: 30 Fahrenheit Temperature: 86.0 ---------------------------------------------------------- Select Code: 1. For Fahrenheit To Celsius 2. For Celsius To Fahrenheit Enter Your Choice:3 Wrong Choice.....Try Again!!! ----------------------------------------------------------
时间: 2023-08-15 16:36:36 浏览: 91
Open-Source_board_for_converting_RaspberryPI_to_Br_EEGwit
以下是使用 switch case 实现温度转换的程序:
```c++
#include <iostream>
using namespace std;
int main() {
int choice;
float temp, result;
while (true) {
cout << "Select Code:\n";
cout << "1. For Fahrenheit To Celsius\n";
cout << "2. For Celsius To Fahrenheit\n";
cout << "3. Exit\n";
cout << "Enter Your Choice: ";
cin >> choice;
if (choice == 3) {
cout << "Exiting...";
break;
}
switch (choice) {
case 1:
cout << "Enter The Value of Fahrenheit Temperature: ";
cin >> temp;
result = (temp - 32) * 5 / 9;
cout << "Celsius Temperature: " << result << "\n";
break;
case 2:
cout << "Enter The Value of Celsius Temperature: ";
cin >> temp;
result = (temp * 9 / 5) + 32;
cout << "Fahrenheit Temperature: " << result << "\n";
break;
default:
cout << "Wrong Choice.....Try Again!!!\n";
break;
}
}
return 0;
}
```
运行程序后,用户可以选择输入选项,然后输入相应的温度值,程序会输出转换结果。如果用户选择退出选项,则程序结束。
阅读全文