-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex3_2.c
56 lines (49 loc) · 1.22 KB
/
ex3_2.c
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
//- 섭씨화씨 교재 예제
//getchar()대신 %*c를 썼을때
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
double convert_celsiu_fahrenheit(double x);
double convert_fahrenheit_celsiu(double y);
double convert_celsiu_fahrenheit(double x){
double h;
h = 9.0 / 5.0 * x + 32;
return h;
}
double convert_fahrenheit_celsiu(double y){
double s;
s = (y - 32.0) * 5.0 / 9.0;
return s;
}
int main(void) {
char command;
double fahrenheit;
double celsius;
while (1) { //무한반복루트 wihle(1)
printf("=====================================\n");
printf("'c' 섭씨온도에서 화씨 온도로 변환\n");
printf("'f' 화씨온도에서 섭씨 온도로 변환\n");
printf("'q' 종료\n");
printf("=====================================\n");
printf("메뉴에서 선택하세요: ");
scanf("%c%*c", &command);
if (command == 'c') {
printf("섭씨온도:");
scanf("%lf%*c", &celsius);
fahrenheit = convert_celsiu_fahrenheit(celsius);
printf("화씨온도:%lf\n", fahrenheit);
}
else if (command == 'f') {
printf("화씨온도:");
scanf("%lf%*c", &fahrenheit);
celsius = convert_fahrenheit_celsiu(fahrenheit);
printf("섭씨온도:%lf\n", celsius);
}
else if (command == 'q') {
break;
}
else {
printf("다시 입력하세요.\n");
}
}
return 0;
}