#include <stdio.h>

 

#define CELSIUS 1
#define FAHRENHEIT 2
#define QUIT 3

 

float Celsius(int); // 화씨를 섭씨로 바꿔준다.

float Fahrenheit(int); // 섭씨를 화씨로 바꿔준다.

void ShowMenu(); // 메뉴를 보여준다.

 

int main()
{

 int num, degree;
 int ERROR = 1, LOOP = 1;

 

 while(LOOP) {

 

   while(ERROR) { //값을 입력받아 옳은 값만을 넘긴다.

        ShowMenu();
        scanf("%d",&num);
  
        if(num == CELSIUS || num == FAHRENHEIT || num == QUIT) 
           break;
 
        printf("You input wrong number. Please input a number from 1 to 3.\n\n");
        }//END while

 

   switch(num){


     case CELSIUS:
      printf("Input a Fahrenheit: ");
      scanf("%d", &degree);
      printf("Celsius is %.1f\n\n", Celsius(degree));
      break;

 

     case FAHRENHEIT:
      printf("Input a Celsius: ");
      scanf("%d", &degree);
      printf("Fahrenheit is %.1f\n\n", Fahrenheit(degree));
      break;

 

     case QUIT:
      return 0;


   }//END switch
 }//END while
}//END main

 

float Celsius(int degree)
{
 return 5*(degree-32)/9;
}

 

float Fahrenheit(int degree)
{
 return 9*degree/5+32;
}

 

void ShowMenu()
{
   printf("1. Fahrenheit(℉) -> Celsius(℃)\n");
   printf("2. Celsius(℃) -> Fahrenheit(℉)\n");
   printf("3. Quit\n");
   printf("Select a Number(1-3): ");
}


+ Recent posts