안녕하세요 오늘은 온도 변환기 입니다. (화씨 <-> 섭씨)
#include <iostream>
using namespace std;
int main() {
int choice;
double temperature;
cout << "Temperature Converter" << endl;
cout << "1. Celsius to Fahrenheit" << endl;
cout << "2. Fahrenheit to Celsius" << endl;
cout << "Enter your choice (1 or 2): ";
cin >> choice;
if (choice != 1 && choice != 2) {
cout << "Invalid choice. Please choose 1 or 2." << endl;
return 1; // Exit with an error code
}
if (choice == 1) {
cout << "Enter temperature in Celsius: ";
cin >> temperature;
double fahrenheit = (temperature * 9.0 / 5.0) + 32.0;
cout << "Temperature in Fahrenheit: " << fahrenheit << endl;
} else {
cout << "Enter temperature in Fahrenheit: ";
cin >> temperature;
double celsius = (temperature - 32.0) * 5.0 / 9.0;
cout << "Temperature in Celsius: " << celsius << endl;
}
return 0; // Exit successfully
}
결과 값
Temperature Converter
1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
Enter your choice (1 or 2): 1
Enter temperature in Celsius: 25
Temperature in Fahrenheit: 77
'Programming language > C++' 카테고리의 다른 글
[C++] 알람시계 구현하기 (0) | 2023.10.07 |
---|---|
[C++] 텍스트 기반 RPG 구현하기 (0) | 2023.10.06 |
[C++] 틱택토 게임 구현 (1) | 2023.10.06 |
[C++]미로 생성기 & 미로 풀이 도구 만들기 (1) | 2023.10.06 |
[C++] 파일 암호화 및 복호화 프로그램 소스 코드 (0) | 2023.10.06 |