问题描述
“计算总数”部分存在一些问题,但我不确定它是什么。除此之外,其他一切都运行良好..我每次都会收到“result_pointer != nullptr”错误。
void Calculatetotal(double pricePergallon,double* totalPtr)
//input price per gallon
//declare,ask and get the number of gallons
//calculate the total
//input/output parameter for the total
{
//declare,ask and get the number of gallons
int numgal = 0;
double tot;
printf("Enter the number of gallons requested: ");
scanf("%d",numgal);
//calculate the total
tot = numgal * pricePergallon;
*totalPtr = tot;
printf("Your total is %f.",totalPtr);
}
Calculatetotal(itemNumber,&total);
(我只是在为我的班级学习编程,所以解释越简单越好。顺便说一句,这不是 C++,只是 C。)
解决方法
ID ab bc ac at abc atn
1 1 2 5 0 0 None
2 0 None 5 0 None None
3 None 0 5 None None 0
应该得到一个指针,所以你对该函数的调用是错误的,应该如下:
scanf
您在调用 scanf("%d",&numGal);
时也有错误,应该如下所示:
printf
您需要使用间接运算符,因为 printf("Your total is %f.",*totalPtr);
是一个指针。