Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.16 KB | None | 0 0
  1. /**
  2.  * Author: Daniel Neri
  3.  * Course: COP 3223 Section 3
  4.  * File:   Program 4 - Problem A: Printing Out a Tire (wheel.c)
  5.  * Date:   10/25/2010
  6.  */
  7. #include <stdio.h>
  8. #include <math.h>
  9. #define PI 3.14159;
  10.  
  11. char fileName[1];
  12. void getFileName();
  13. int main();
  14.  
  15. int main()
  16. {
  17.     int tripMinutes = 0;
  18.     int tireRadius = 0;
  19.     int index = 0;
  20.     double fuelEfficiencies[10000];
  21.    
  22.     double circumference;
  23.     double distanceInches;
  24.     double gasConsumed;
  25.     double milesTraveled;
  26.     double averageMPG;
  27.     double inchesToMiles;
  28.    
  29.     // file handling commands
  30.     getFileName();
  31.    
  32.     FILE *ifp;
  33.    
  34.     ifp = fopen(fileName, "r");
  35.    
  36.     fscanf(ifp, "%d%d", &tripMinutes, &tireRadius);
  37.    
  38.    
  39.     for (index=0; index<(60*tripMinutes); index++)
  40.     {
  41.         double seconds_tireRevolutions = 0;
  42.         double seconds_gasConsumed = 0;
  43.        
  44.         fscanf(ifp, "%lf%lf", &seconds_tireRevolutions, &seconds_gasConsumed);
  45.        
  46.        
  47.                      
  48.        
  49.         if(seconds_gasConsumed == 0 && seconds_tireRevolutions>0)
  50.         {
  51.              fuelEfficiencies[index] = 100;            
  52.         }
  53.         else if(seconds_tireRevolutions<=0 && seconds_gasConsumed == 0)
  54.         {
  55.              fuelEfficiencies[index] = 0;
  56.         }else{
  57.              
  58.             /**
  59.              * Mathematical calculations
  60.              */
  61.            
  62.             circumference = tireRadius * 2 * PI;    
  63.            
  64.             distanceInches = circumference * seconds_tireRevolutions;  
  65.            
  66.             inchesToMiles = distanceInches / 12 / 5280;    
  67.            
  68.             milesTraveled = inchesToMiles;
  69.            
  70.             averageMPG = milesTraveled / seconds_gasConsumed;
  71.            
  72.             fuelEfficiencies[index] = averageMPG;
  73.         }
  74.     }
  75.              
  76.     double total_tireRevolutions = 0;
  77.     double total_gasConsumed = 0;        
  78.     int newFuelEfficiencies[20];
  79.     int temp=0;
  80.     index=0;
  81.     while(index<(tripMinutes))
  82.     {
  83.           for(temp=(300*index);temp<(index*300);temp++)
  84.         {
  85.                                                                                  
  86.                            
  87.         }      
  88.     }
  89.     for(index=0;index<(60*tripMinutes);index++)
  90.     {
  91.          if(index<300)
  92.          {
  93.               temp= temp+fuelEfficiencies[index];
  94.          }                                      
  95.          printf("currentval: %lf\n", fuelEfficiencies[index]);
  96.     }
  97.    
  98.     int row = 0;
  99.     int col = 0;
  100.     int labels = 95;
  101.     // Loop through each row.
  102.     for (col=(0); col<20; col++)
  103.     {
  104.    
  105.         //
  106.         for (row=0; row<=34; row++)
  107.         {
  108.             if(row==0)
  109.             {
  110.                  printf("%-4d", labels);
  111.                  labels = labels-5;
  112.             }
  113.            
  114.         }
  115.         printf("\n");
  116.        
  117.     }
  118.    
  119.     printf("    -----------------------------------\n");
  120.     printf("    00-05 05-10 10-15 15-20 20-25 25-30\n\n");
  121.     fclose(ifp);
  122.     system("PAUSE");
  123. }
  124.  
  125. void getFileName()
  126. {
  127.      printf("What file stores the car data?\n");
  128.      scanf("%s", &fileName);
  129.      printf("\n\n");
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement