daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. float average(float i);
  5.  
  6. void main()
  7. {
  8.     // Declare the variables
  9.     FILE* acc;
  10.     int array[24];
  11.     int array2[24];
  12.     int i;
  13.     int j;
  14.     int k;
  15.     float result = 0, result2 = 0;
  16.     int ret, ret2;
  17.     int lesser = 0;
  18.     int count = 0, count2 = 0, count3 = 0;
  19.  
  20.     //opens the file agian to append
  21.     acc = fopen("accidents.txt", "a");
  22.  
  23.     printf("Please Enter Data for Year 1\n\n");
  24.     //the for loop to get the the info and store it
  25.     for (i = 0; i < 24; i++)
  26.     {
  27.         printf("Please Enter Road Accident data for the hour starting at %d am: ", count);
  28.         scanf("%d", &array[i]);
  29.  
  30.         //get the average of the array
  31.         result += array[i];
  32.  
  33.         //this increments the count by 1
  34.         count++;
  35.  
  36.         //to get the least
  37.         if (lesser < array[i])
  38.         {
  39.             lesser = array[i];
  40.         }
  41.     }
  42.  
  43.     //the for loop to get the second info and store it
  44.     printf("\nPlease Enter Data for Year 2\n\n");
  45.     for (j = 0; j < 24; j++)
  46.     {
  47.  
  48.         printf("Please Enter Road Accident data for the hour starting at %d am: ", count2);
  49.         scanf("%d", &array2[j]);
  50.  
  51.         //get the average of the array
  52.         result2 += array2[j];
  53.  
  54.         //this increments the count by 1
  55.         count2++;
  56.     }
  57.  
  58.     //header
  59.     printf("\n\nHours   ThisYear   LastYear\n");
  60.     //1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  61.     //23 22 1 2 3 4 5 6 7 8 9 1 2 3 5 6 5 3 4 5 6 7 1 3
  62.  
  63.     //display the array
  64.     //for loop prints the arrays
  65.     for (i = 0; i < 24; i++)
  66.     {
  67.  
  68.         printf("\n");
  69.         printf("%-2d am %7d %9d", count3, array[i], array2[i]);
  70.         //printf("%d", array[i]);
  71.         count3++;
  72.  
  73.         //printing the the arrays TO THE FILE
  74.         if (acc != NULL)
  75.         {
  76.             //printf("%s %d %d %f\n", empl.E_Name, empl.E_Number, empl.Hours_Week, empl.H_Rate);
  77.             //print it to the the file employee.txt
  78.             fprintf(acc, "\n");
  79.             fprintf(acc, "%-2d am %7d %9d", count3, array[i], array2[i]);
  80.  
  81.         }
  82.  
  83.     }
  84.  
  85.     //display the average of of road road accidents for the thiis year
  86.     result = result / 24;
  87.     ret = average(result);
  88.  
  89.     //display the average of of road road accidents for the Lastyear year
  90.     result2 = result2 / 24;
  91.     ret2 = average(result2);
  92.  
  93.     //printing the AVERAGE TO THE FILE
  94.     if (acc != NULL)
  95.     {
  96.         fprintf(acc, "\n");
  97.         fprintf(acc, "The Average Road accident for this year is: %f", result);
  98.         fprintf(acc, "\n");
  99.         fprintf(acc, "The Average Road accident for this year is: %f", result2);
  100.     }
  101.  
  102.     if (acc != NULL)
  103.         fclose(acc);
  104.     getch();
  105. }
  106. //function for the average
  107. float average(float i)
  108. {
  109.     printf("\n\nThe Average Road accident for this year is: %0.2f", i);
  110.     return i;
  111. }
RAW Paste Data
Top