“计算总数”部分有一些问题,但我不确定它是什么。除了它,其他的都运行得很好..我每次都会收到"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++ btw,而是C。)
发布于 2021-04-23 00:23:48
scanf
应该得到一个指针,所以你对函数的调用是错误的,应该如下所示:
scanf("%d", &numGal);
您对printf
的调用中也有一个错误,应该如下所示:
printf("Your total is %f.", *totalPtr);
由于totalPtr
是一个指针,因此需要使用间接操作符。
https://stackoverflow.com/questions/67216964
复制相似问题