hey im just having a little trouble with the problem solving behind this assignment, can't quite get my loops to output and save what I want them too...
anyways the goal is to use an input file with recorded tire revolutions/gas used to average gas mile and output a graph of it in 5 minute intervals.
anywho, this is the code i've got so far... trying to have it average out 900 seconds into 3 5-min intervals
Code:
#include <stdio.h>
#define PI 3.14159
#define INCH_IN_MILE 63360
int main() {
FILE *ifp;
int minTrip, intervals;
double revs, gas, mileage[6], fueleffic, curMileage[60], totMileage, radius;
// Open file and read in data
ifp = fopen("sample.txt","r");
fscanf(ifp, "%d%d", &minTrip, &radius);
printf("min in trip = %d/n", minTrip);
printf("radius = %d", radius);
intervals = minTrip/5;
int cases;
for (cases=0; cases<intervals; cases++) {
double totRevs = 0, totGas = 0;
int i;
for (i=1; i<=300; i++) {
fscanf(ifp, "%lf%lf", &revs, &gas);
totRevs = revs+totRevs;
totGas = gas+totGas;
}
radius = radius/INCH_IN_MILE; // MAY BE INT!?!?
mileage[cases] = (2*PI*radius*totRevs)/totGas;
//printf("avg mil = %lf, %lf, %lf", mileage[0], mileage[1], mileage[2]);
}
system("PAUSE");
return(0);
}
and here is the sample file...