0

コードを実行するたびに、52 行目と 61 行目で同じエラー メッセージが表示され続けます。

#include<stdio.h>
#include<math.h>

double getinput(void);
double calcwindchillold(double v, double t);
double calcwindchillnew(double v, double t);
void printResults(double windchillold, double windchillnew);

int main(void)
{
    double v = 0;
    double t = 0;
    double windchillold = 0;
    double windchillnew = 0;

    v = getinput();
    t = getinput();
    windchillold = calcwindchillold(v,t);
    windchillnew = calcwindchillnew(v,t);
    return 0;
}
double getinput(void)
{
    double v,t;
    printf("Input the wind speed in MPH: ");
    scanf("%lf", &v);
    printf("Input the temperature in degrees Fahrenheit: ");
    scanf("%lf", &t);


    return v,t;

}

double calcwindchillold(double v, double t)
{
    double windchillold;

    windchillold = ((0.3 * v^0.5) + 0.474 - (0.02 * v) * (t - 91.4) + 91.4);
// in the line above this is the error.

    return windchillold;
}

double calcwindchillnew(double v, double t)
{
    double windchillnew;

    windchillnew = 35.74 + 0.6215*t - 35.75*(v^0.16) + 0.4275 * t * v^0.16;
// in the line above this is the second error.

    return windchillnew;
}

void printResults(double windchillold, double windchillnew)
{
    printf("The wind chill using the old formula is: %lf F\n", windchillold);
    printf("The wind chill using the new formula is: %lf F\n", windchillnew);
}

これにより、デバッグ システムに次のように表示されます。

「ダブル」エラーが発生している他のスクリプトも調べましたが、その情報を使用して自分自身を助けることができませんでした。

私が調べたのはおそらく単純なことだと思います。

4

4 に答える 4

2

C^では、指数演算子ではなく排他的 OR 演算子 (XOR) です。2 つの浮動小数点値を XOR することはできません。

pow(3)累乗するには、 の関数を使用できますmath.h

于 2013-02-08T21:09:36.223 に答える
1
#include <math.h>
double pow( double base, double exp );

Cでは複数の値を返すことができないので、このように単一の関数を実行してください...

double getinput(const char* message) {
    double retval;
    printf("%s: ", message);
    scanf("%lf", &retval);
    return retval;
}

ポインターと OS を習得する方法について学習する前に、コードをできるだけ単純に保つようにしてください。

それが役に立てば幸い :)

于 2013-02-08T21:31:14.217 に答える
1

ビット演算子は、浮動小数点型のオペランドでは機能しません。オペランドは整数型である必要があります。

(C99、6.5.11p2 ビット単位の排他的 OR 演算子) 「各オペランドは整数型でなければなりません。」

^C のビットごとの排他的 OR 演算子です。

電源操作を使用するには、で宣言されているpowおよび関数を使用します。powfmath.h

于 2013-02-08T21:09:36.393 に答える
0

別の問題:

return v,t;

C では、複数の戻り値を持つことはできません。

これは、呼び出し時に out パラメーターとして行うか、別の関数を作成することができます。例えば:

void getinput(double* v_out, double* t_out)
于 2013-02-08T21:12:50.203 に答える