Code:
#include <stdio.h>
double calculate_tp(int quantity, double up_dollars, double up_pounds, double *tpa, double *tpb);
int main(void)
{
char again;
double up_dollars = 30.0, up_pounds = 15.0; /*Unit price*/
int quantity;
double tp_dollars,tp_pounds; /* Total price */
for (again = 'y'; again != 'n'; scanf(" %c",&again)){
printf("Unit cost is %.2lf dollars or %.2lf pounds \n",up_dollars,up_pounds);
printf("Enter quantity>");
scanf(" %d",&quantity);
printf("Quantity %d \n \n",quantity);
calculate_tp(quantity,up_dollars,up_pounds,&tp_dollars,&tp_pounds);
printf("Total in dollars %.2lf \n",&tp_dollars);
printf("Total in pounds %.2lf \n \n",&tp_pounds);
printf("Run program again?");
}
return(0);
}
double calculate_tp(int quantity, double up_dollars, double up_pounds, double *tpa, double *tpb)
{
*tpa = quantity * up_dollars;
printf("Test print total dollars %.2lf \n",*tpa);
*tpb = quantity * up_pounds;
printf("Test print total pounds %.2lf \n",*tpb);
}
The test printf's work. However the printfs in the main for the totals display zero always. Any ideas as to why the value doesnt seem to pass to tp_dollars and tp_pounds?
The program doesnt really make much sense but I'm just trying to learn using pointers with functions.