2014-03-04 2 views
0

화씨를 섭씨로 변환하려고하면 C로 표시된 내 온도 변환 프로그램이 계속 출력됩니다. 섭씨에서 화씨로의 변환은 잘 작동하는 것 같습니다. 두 함수와 부분 모두 똑같은 일을했지만 두 번째 변환에서는 0을 계속 유지합니다. 누군가 나를 도우 려는가 또는 내가 뭘 잘못하고 있는지 말해 줄 수 있습니까? 당신이C 섭씨로 화씨로 0을 출력하는 온도 변환 프로그램

scanf("%f", &*Celsius); 

&*가 사용하고 여기에

#include <stdio.h> 

//Function Declarations 

float get_Celsius (float* Celsius);  //Gets the Celsius value to be converted. 
void to_Fahrenheit (float cel);   //Converts the Celsius value to Fahrenheit and prints the new value. 
float get_Fahrenheit (float* Fahrenheit); //Gets the Fahrenheit value to be converted. 
void to_Celsius (float fah);    //Converts the Fahrenheit value to Celsius and prints the new value. 

int main (void) 
{ 
    //Local Declarations 
    float Fahrenheit; 
    float Celsius; 
    float a; 
    float b; 

    //Statements 
    printf("Please enter a temperature value in Celsius to be converted to Fahrenheit:\n"); 
    a = get_Celsius(&Celsius); 
    to_Fahrenheit(a); 
    printf("Please enter a temperature value in Fahrenheit to be converted to Celsius:\n"); 
    b = get_Fahrenheit(&Fahrenheit); 
    to_Celsius(b); 

    return 0; 
} //main 

float get_Celsius (float* Celsius) 
{ 
    //Statements 
    scanf("%f", &*Celsius); 
    return *Celsius; 
} 

void to_Fahrenheit (float cel) 
{ 
    //Local Declarations 
    float fah; 

    //Statements 
    fah = ((cel*9)/5) + 32; 
    printf("The temperature in Fahrenheit is: %f\n", fah); 
    return; 
} 

float get_Fahrenheit (float* Fahrenheit) 
{ 
    //Statements 
    scanf("%f", &*Fahrenheit); 
    return *Fahrenheit; 
} 

void to_Celsius (float fah) 
{ 
    //Local Declarations 
    float cel; 

    //Statements 
    cel = (fah-32) * (5/9); 
    printf("The temperature in Celsius is: %f\n", cel); 
    return; 
} 
+0

변경은 오 와우 난 꽤 많은 광산과 동일 질문을 보지 못했다. 나는이 웹 사이트에 처음 온 복제본에 대해 사과드립니다. – user3377510

+0

적어도 다음에 알 수 있습니다. 그러나 일반적으로이 규칙과 같은 대부분의 초급 유형 문제는 최소한 한 번 (이 경우에는 여러 번) 요청되었으며 게시하기 전에 가능한 많은 관련 질문을 표시해야합니다. –

답변

5
cel = (fah-32) * (5/9); 

, 5/9는 결과가


그리고 여러 줄의 5.0/9로 변경, 0이며, 정수 부서입니다 필요하지 않음, 간단하게 scanf("%f", Celsius); 것이다 영형.

+0

_scanf ("% f", 섭씨); _ 작동하지 않을 것으로 생각됩니다. 적어도 당신은 & –

+0

이 필요합니다. 나는 그것이 어리석은 어떤 것이라는 것을 알았 기 때문에 고맙습니다. 그러나 그것이 무엇인지 알 수 없었습니다. 아마도 5.0/9로 만든 십진수를 곱하면됩니다. 그럼에도 불구하고, 당신의 도움에 감사드립니다. – user3377510

+0

@Abhay'Celsius'는 그 함수에'float *'형을 가지고 있습니다. 왜냐하면'main'에서'Celsius'라는 이름이'float' 타입이기 때문에 변수 이름을 잘못 지정하는 것입니다. –

1
cel = (fah-32) * (5/9); 

5/9int/int 그리고 당신에게 int 그래서 그 0 인 결과를 줄 것이다.

cel = (fah-32) * (5.0/9.0); 

또는

cel = (fah-32) * ((float)5/(float)9);