我想学习C,并且在我最近的代码中遇到了一个我不明白的编译错误。我真的不明白错误是什么意思,所以我无法解决这个问题。我做了大量的谷歌搜索,但不明白我遇到的解释。'*'的类型参数无效(有'双')C
有人可以澄清吗?
错误:
代码:
#include <stdio.h>
#include <unistd.h>
#include "plant.h"
double watercredit = 0.0;
int needwater = 200;
double wateredamount = 0.0;
int main()
{
watercredit=215.00;
while(watercredit > 0.0)
{
watercredit--;
if(watercredit < needwater)
{
printf("You need to water the plant!\n");
printf("enter amount of water:\n");
scanf("%lf", wateredamount);
watered(&wateredamount);
//watercredit = watercredit + wateredamount;
wateredamount = 0;
}
if(watercredit == 0)
{
printf("You plant died!");
return 0;
}
printf("Watercredit: %lf\n", watercredit);
sleep(1);
}
return 0;
}
//takes the amount of water added and increases credit
void watered(double* amount)
{
*watercredit = *watercredit + amount;
}
Plant.h:
void watered(double* amount);
无关的错误,但'的scanf( “%LF”,wateredamount);'应'的scanf( “%LF”,&wateredamount);'。另外请注意,不需要通过引用该函数来传递'wateredamount'。 –