Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Author: Daniel Neri
- * Course: COP 3223 Section 3
- * File: Program 4 - Problem A: Printing Out a Tire (wheel.c)
- * Date: 10/25/2010
- */
- #include <stdio.h>
- #include <math.h>
- #define PI 3.14159;
- char fileName[1];
- void getFileName();
- int main();
- int main()
- {
- int tripMinutes = 0;
- int tireRadius = 0;
- int index = 0;
- double fuelEfficiencies[10000];
- double circumference;
- double distanceInches;
- double gasConsumed;
- double milesTraveled;
- double averageMPG;
- double inchesToMiles;
- // file handling commands
- getFileName();
- FILE *ifp;
- ifp = fopen(fileName, "r");
- fscanf(ifp, "%d%d", &tripMinutes, &tireRadius);
- for (index=0; index<(60*tripMinutes); index++)
- {
- double seconds_tireRevolutions = 0;
- double seconds_gasConsumed = 0;
- fscanf(ifp, "%lf%lf", &seconds_tireRevolutions, &seconds_gasConsumed);
- if(seconds_gasConsumed == 0 && seconds_tireRevolutions>0)
- {
- fuelEfficiencies[index] = 100;
- }
- else if(seconds_tireRevolutions<=0 && seconds_gasConsumed == 0)
- {
- fuelEfficiencies[index] = 0;
- }else{
- /**
- * Mathematical calculations
- */
- circumference = tireRadius * 2 * PI;
- distanceInches = circumference * seconds_tireRevolutions;
- inchesToMiles = distanceInches / 12 / 5280;
- milesTraveled = inchesToMiles;
- averageMPG = milesTraveled / seconds_gasConsumed;
- fuelEfficiencies[index] = averageMPG;
- }
- }
- double total_tireRevolutions = 0;
- double total_gasConsumed = 0;
- int newFuelEfficiencies[20];
- int temp=0;
- index=0;
- while(index<(tripMinutes))
- {
- for(temp=(300*index);temp<(index*300);temp++)
- {
- }
- }
- for(index=0;index<(60*tripMinutes);index++)
- {
- if(index<300)
- {
- temp= temp+fuelEfficiencies[index];
- }
- printf("currentval: %lf\n", fuelEfficiencies[index]);
- }
- int row = 0;
- int col = 0;
- int labels = 95;
- // Loop through each row.
- for (col=(0); col<20; col++)
- {
- //
- for (row=0; row<=34; row++)
- {
- if(row==0)
- {
- printf("%-4d", labels);
- labels = labels-5;
- }
- }
- printf("\n");
- }
- printf(" -----------------------------------\n");
- printf(" 00-05 05-10 10-15 15-20 20-25 25-30\n\n");
- fclose(ifp);
- system("PAUSE");
- }
- void getFileName()
- {
- printf("What file stores the car data?\n");
- scanf("%s", &fileName);
- printf("\n\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement