Guest User

Untitled

a guest
Dec 11th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. #define FIRST_CAR_LENGTH 10
  5. #define NORMAL_CAR_LENGTH 8
  6. #define CAR_CAPACITY 4
  7.  
  8. int main() {
  9.  
  10. int num_of_trains, cars;
  11. int track_length, train_length;
  12. int lowest_cars, total_train_length;
  13. int persons;
  14. int tl, max_tl, max_persons;
  15. float ratio, sum1, sum2, avg, array_persons[100], array_train[100];
  16. int i, train_cars;
  17. int x, g, h;
  18.  
  19. printf("What is the total length of the track, in feet?\n");
  20. scanf("%d", &track_length);
  21.  
  22. printf("What is the maximum length of the train, in feet?\n");
  23. scanf("%d", &train_length);
  24.  
  25. i = 0;
  26. max_persons = 0;
  27. lowest_cars = 0;
  28. cars = 0;
  29.  
  30. max_tl = (track_length * .25);
  31.  
  32. // For loop for max train length
  33. for(tl=10; tl <= train_length; tl+=8) {
  34. cars++;
  35. // 250 / 42 = 5
  36. num_of_trains = max_tl/train_length;
  37. // 5*4*5=100
  38. persons = num_of_trains*CAR_CAPACITY*cars;
  39. // 5*42 = 210
  40. total_train_length = num_of_trains*train_length;
  41. // 80/210
  42. ratio = (persons*1.00)/total_train_length;
  43.  
  44. array_persons[i]=persons;
  45.  
  46. array_train[i]=total_train_length;
  47.  
  48. i++;
  49. }
  50.  
  51. // Finding the max number of people
  52. for(g=0; g<i; g++) {
  53. if(array_persons[g] > max_persons) {
  54. max_persons = array_persons[g];
  55. }
  56. }
  57.  
  58. // Finding the lowest number of cars for the train
  59. for(h=0; h<i; h++) {
  60. if(array_train[h] > lowest_cars) {
  61. lowest_cars = array_train[h];
  62. }
  63. }
  64.  
  65. // Finding the avg for persons
  66. sum1 = 0;
  67. for(x=0; x<i; x++)
  68. sum1+=array_persons[x];
  69.  
  70. //Finding the avg for cars
  71. sum2 = 0;
  72. for(x=0; x<i; x++)
  73. sum2+=array_train[x];
  74.  
  75. avg = (sum1/i)/(sum2/i);
  76.  
  77. printf("Your ride can have at most %d people at one time.\n", max_persons);
  78.  
  79.  
  80. printf("This can be achieved with trains of %d cars,\n", lowest_cars);
  81.  
  82.  
  83. printf("AVG Ratio: %1.2f", avg);
  84.  
  85. system("pause");
  86.  
  87. return 0;
  88. }
Add Comment
Please, Sign In to add comment