0
#include <stdio.h>


void temperature(double x) {
    double f = ((9.0/5)*(x))+32;
    return f;
}

int main (int argc , char * argv[]){
    printf("Please Enter a degree in Celsius =>");

    if (argc > 1){
        double c = atolf(argv[1]);

        double result = temperature(c);

        printf("%lf celcius in fahrenheit is %lf",c,result);

        }
    else {
        printf("Please enter a temperature in degrees celius");
    }

}

错误(在cygwin中编译时)我认为问题出在void方法温度中:我试图在温度方法中返回一个双精度值。谢谢您的帮助。

$ gcc -o temperature temperature.c
temperature.c: In function 'temperature':
temperature.c:6: warning: 'return' with a value, in function returning void
temperature.c: In function 'main':
temperature.c:15: error: void value not ignored as it ought to be
4

1 回答 1

1

由于函数正在返回double,因此您需要相应地更改其返回类型:

double temperature(double x) {
^^^^^^
于 2013-06-29T07:01:56.653 回答