Description You have been hired by a startup that is designing a vehicle track-
ID: 3887399 • Letter: D
Question
Description You have been hired by a startup that is designing a vehicle track- ing device for fleet vehicles, such as delivery trucks. The device tracks for each trip how much the vehicle has travelled and how long the trip lasted. The device then determines the average speed of the vehicle, and also gives warnings if the vehicle's av- erage speed was too high at any trip Input Your program's input will be given through stdin, which means you can read the input with scanf) The input will start with an integer representing the the number of trips that were recorded. This will be followed by a series of integers, containing the distance and duration of each trip. Here is an example input: 3 55 65 30 35 45 50 On the example above, the vehicle made 3 trips. The first trip was 55 miles and lasted 65 minutes. The second trip was 30 miles, and lasted 35 minutes. The third trip was 45 miles, and lasted 50 minutesExplanation / Answer
HI, here's the complete code with comments,
#include <stdio.h>
int main(void) {
int trips;
scanf("%d",&trips);
int n=trips;
int totalDistance=0;
int totalTime=0;
float totalTripSpeed=0.0;
while(trips--) // iterating for number of trips
{
int distance;
int singleTriptime;
float singleTripSpeed;
scanf("%d",&distance); //taking distance input
scanf("%d",&singleTriptime); //taking time input
double timeInhours=(double)singleTriptime/60; //minutes to hours
singleTripSpeed=distance/timeInhours; //speed for each trip
if(singleTripSpeed>=60)
printf("WARNING: speed above 60mph in trip number %d ",trips+1); //WARNING
totalTripSpeed+=singleTripSpeed;
}
if (totalTripSpeed/n>=60) //WARNING
printf("WARNING:average speed is %f mph which is more than 60mph",totalTripSpeed/n);
else
printf("average speed is %f mph",totalTripSpeed/n); //average speed printing
return 0;
}
Thumbs up if this was hepful, otherwise let me know in comments.