簡體   English   中英

找不到為什么我的顯示值始終為0

[英]Can't find out why my display value is always 0

使用我們實驗室功能的開爾文到C或F轉換程序。 我不知道為什么我一直得到0作為輸出。 我認為這與我傳遞/返回值的方式有關。 我可能還沒有得到回報?

#include <stdio.h>
#include <ctype.h>


float KtoC(float kel)
{
    kel = - 273;

    return(kel);
}

float KtoF(float kel)
{
    kel = (9 * kel / 5) + 32;

    return(kel);
}

float GetKelvin(float kel)
{
    printf("Temperature Conversion Program\n");
    printf("Please enter a temperature in Degrees Kelvin:");
    scanf("%f%*c", &kel);

    return(kel);
}

char GetConvType(char &ctype)
{
    do
        {
        printf("Convert to Celcius (c) or Fahrenheit (f): ");
        scanf("%c%*c", &ctype);

        ctype = tolower(ctype);

        } while(ctype != 'c' && ctype != 'f');

    return(ctype);
}

float GetConvTemp(float kel)
{
    char ctype;

    ctype = GetConvType(ctype);

    if(ctype == 'c')
    {
        return (KtoC(kel));
    }
    else
    {
        return (KtoF(kel));
    }
}   

void DisplayResults(float x)
{
    printf("This is the temp converted %f", x);

    return;
}



int main()
{
    float kel, x;
    char ctype;

    GetKelvin(kel);
    GetConvType(ctype);
    GetConvTemp(kel);
    DisplayResults(kel);

    return(0);

}
--- xorg.cpp    2017-05-19 00:48:56.000000000 +0900
+++ x.cpp   2017-05-19 00:50:23.000000000 +0900
@@ -4,19 +4,19 @@

 float KtoC(float kel)
 {
-   kel = - 273;
+   kel -= 273.0;

    return(kel);
 }

 float KtoF(float kel)
 {
-   kel = (9 * kel / 5) + 32;
+   kel = (9.0 * KtoC(kel) / 5.0) + 32.0;

    return(kel);
 }

-float GetKelvin(float kel)
+float GetKelvin(float &kel)
 {
    printf("Temperature Conversion Program\n");
    printf("Please enter a temperature in Degrees Kelvin:");
@@ -39,7 +39,7 @@
    return(ctype);
 }

-float GetConvTemp(float kel)
+float GetConvTemp(float &kel)
 {
    char ctype;

@@ -71,8 +71,7 @@

    GetKelvin(kel);
    GetConvType(ctype);
-   GetConvTemp(kel);
-   DisplayResults(kel);
+   DisplayResults(GetConvTemp(kel));

    return(0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM