输入变量的冲突类型?我的功能是否正确使用?

时间:2016-09-22 01:28:01

标签: c variables types

编译器告诉我,根据我对函数的定义,我的类型存在冲突' input_instructions"?我有所有变量的double类型。我是新手,所以很可能我做错了,这段代码可能很糟糕。如果我的功能不正确你能告诉我原因吗?如果你知道我的意思,我不知道如何在main函数中本地化变量。没有足够的上下文来发布问题。来吧。

#include <stdio.h>
#include <stdlib.h>


void input_instructions(double *vf, double *vi);
double compute_acc(double vf, double vi);

int main()
{
    double vf,vi,t,a;

    input_instructions(&vf,&vi);

    a=compute_acc(vf,vi);

    t = (vf - vi)/a;

    printf("The constant acceleration of the cyclist is %.2f and it will take him %.2f minutes/seconds/"
            "to come to rest with an initial velocity of 10mi/hr.\n", a, t);
}

void input_instructions(double vf, double vi)
{
    printf("This program will calculate the rate of accleration and the time it takes/"
            "the cyclist to come to rest\n");
    printf("Enter final velocity=>");
    scanf("%lf", &vf);
    printf("Enter final velocity");
    scanf("%lf", &vi);
}

double compute_acc(double vf, double vi)
{
    int t = 1;
    double a;
    a = (vf-vi)/t;
    return (a);
}

它一直告诉我要添加更多细节,这样我才能继续输入,直到我可以提交我的问题。显然我的帖子代码太多而且背景不够,但我认为你明白了。

1 个答案:

答案 0 :(得分:0)

input_instructions(安培; VF,&安培; 6); &amp; vf和&amp; vi是地址 你应该使用指针类型

这是你的功能声明: void input_instructions(double * vf,double * vi);

但功能体是: void input_instructions(double vf,double vi){...};