1
votes

There's some problem with the 'calculate the total' part but I'm unsure what it is. Everything else runs fine besides it.. I get the "result_pointer != nullptr" error everytime.

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);
 }

unsure if it matters, but I called it in another function definition like so:

CalculateTotal(itemNumber, &total);

(I'm just learning programming for my class, so the simpler the explanation, the better. This is not C++ btw, just C.)

1
scanf("%d", numGal); You need to pass an address here. scanf("%d", &numGal); - Johnny Mopp

1 Answers

0
votes

scanf should get a pointer, so your call to the function is wrong and should be as follows:

scanf("%d", &numGal);

You also have a bug in your call to printf, which should be as follows:

printf("Your total is %f.", *totalPtr);

You need to use the indirection operator due to the fact that totalPtr is a pointer.