我想學習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'。 –