I wrote a simple code to calculate the total cost of gas for a week.
#include <stdio.h>
int main () {
#define MILES_PER_GALLO N 23;
#define MILES_TO_SCHOOL 25;
double cost_per_gallon ;
double trips;
printf("How much does gas cost this week?\n");
scanf("%lf", &cost_per_gallo n);
printf("How many times does John have to drive to campus this week?\n");
scanf("%lf", &trips);
trips = trips * 2;
double miles = MILES_TO_SCHOOL * trips;
double gallons = miles / MILES_PER_GALLO N
double cost = cost_per_gallon * gallons;
printf("John must spend $%lf on gas this week.\n", &cost);
}
upon compiling and running it, the final print gives "John must spend $0.00000 on gas this week."
Why?
#include <stdio.h>
int main () {
#define MILES_PER_GALLO N 23;
#define MILES_TO_SCHOOL 25;
double cost_per_gallon ;
double trips;
printf("How much does gas cost this week?\n");
scanf("%lf", &cost_per_gallo n);
printf("How many times does John have to drive to campus this week?\n");
scanf("%lf", &trips);
trips = trips * 2;
double miles = MILES_TO_SCHOOL * trips;
double gallons = miles / MILES_PER_GALLO N
double cost = cost_per_gallon * gallons;
printf("John must spend $%lf on gas this week.\n", &cost);
}
upon compiling and running it, the final print gives "John must spend $0.00000 on gas this week."
Why?
Comment