1

私のプログラムが同じ力を計算し続けるのはなぜですか? 式を正しく使用していますが、なぜ 127 ダインの力が得られるのかわかりません。どんな助けでもいただければ幸いです

#include <stdio.h>
#include <math.h>
const double gravity_constant = 6.673;
void force_calculate(double a, double b, double c, double d);
void input(double *a, double *b, double *c);
void display(double a, double b, double c, double d);
int main(int argc, char * argv[])
{
    double mass_1 = 0;
    double mass_2 = 0;
    double distance = 0;
    double force = 0;

    input(&mass_1, &mass_2, &distance);
    force = force_calculate(mass_1, mass_2, distance, force);
    display(mass_1, mass_2, distance, force);

    return 0;
}

void force_calculate(double a, double b, double c, double d)
{
    d = (gravity_constant*a*b)/(c*c);
    return;
}
void input(double *a, double *b, double *c)
{
    printf("What is the first mass in grams?\n");
    scanf("%lf", a);
    printf("What is the second mass in grams?\n");
    scanf("%lf", b);
    printf("What is the distance between the two masses in centimeters\n");
    scanf("%lf", c);
}
void display(double a, double b, double c, double d)
{
    printf("%fg is the first mass\n", a);
    printf("%fg is the second mass\n", b);
    printf("%fcm is the distance between the two masses\n", c);
    printf("%f is the force in dynes between both masses\n", d);
    return;
}
4

5 に答える 5

1

このプログラムを実行すると、次のランタイム エラーが発生します。

dc:15:11: エラー: void 値が無視されないはずです

これで解決できると思います。

#include <stdio.h>
#include <math.h>
const double gravity_constant = 6.673;
double force_calculate(double a, double b, double c);
void input(double *a, double *b, double *c);
void display(double a, double b, double c, double d);
int main(int argc, char * argv[])
{
    double mass_1 = 0;
    double mass_2 = 0;
    double distance = 0;
    double force = 0;

    input(&mass_1, &mass_2, &distance);
    force = force_calculate(mass_1, mass_2, distance);
    display(mass_1, mass_2, distance, force);

    return 0;
}

double force_calculate(double a, double b, double c)
{
    double force;
    force = (gravity_constant*a*b)/(c*c);
    return force;
}
void input(double *a, double *b, double *c)
{
    printf("What is the first mass in grams?\n");
    scanf("%lf", a);
    printf("What is the second mass in grams?\n");
    scanf("%lf", b);
    printf("What is the distance between the two masses in centimeters\n");
    scanf("%lf", c);
}
void display(double a, double b, double c, double d)
{
    printf("%fg is the first mass\n", a);
    printf("%fg is the second mass\n", b);
    printf("%fcm is the distance between the two masses\n", c);
    printf("%f is the force in dynes between both masses\n", d);
    return;
} 
于 2013-10-22T03:04:06.340 に答える