Hello all. I am needing to do a mpg calculation using pointers in both the calculations and the print statement. I have the basic code set up but I am not sure how to set up the pointers so they go through the values assigned in the arrays and then print the received values stored in the mpg array. Help would be great
Code:
#include <stdio.h>
int main (){
#define max 10
double miles [max] = {240.5, 300.0, 189.6, 310.6, 280.7, 216.9, 199.4, 160.3, 177.4, 192.3};
double gallons [max] = {10.3, 15.6, 9.7, 14, 16.3, 15.7, 14.9, 10.7, 9.3, 9.4};
double mpg [max];
double *gPtr, *mPtr, *nPtr;
int i;
gPtr= &gallons;
mPtr= &miles;
nPtr= &mpg;
for (i=0; i<max; i++){
*(nPtr)= *(mPtr)/ *(gPtr);
}
for (i=0; i<max; i++){
printf ("The mpg is %f\n", *nPtr);
}