222k views
4 votes
c programming Write a program that will read in a velocity of a vehicle in miles per hour, and an amount of time traveled in minutes (both of datatype double). Then in a user defined function called CalcPrintDistance, calculate the distance traveled by the vehicle and print the distance traveled (both from the function) to the screen in miles (using 2 decimal places). CalcPrintDistance should have two parameters: the velocity and the amount of time traveled. oThe function should have different variable names from Main.oCalcPrintDistance should not return any values to main.oDo your calculations all in the function. Including the conversion of minutes to hours.Test your program with the following values:Velocity: 68.2 mphTime traveled: 34.6 minutes

User Ahill
by
5.9k points

1 Answer

4 votes

Answer:

// program in C

#include <stdio.h>

// function to calculate distance traveled

void CalcPrintDistance(double vel,double min)

{

// calculate distance

double dis=(vel*min)/60;

// print distance

printf("Distance traveled by vehicle is:%0.2lf miles",dis);

}

// main function

int main(void) {

// variable

double velocity,minutes;

printf("Enter the velocity of vehicle(miles per hour):");

// read velocity

scanf("%lf",&velocity);

printf("Enter the time traveled(in minutes):");

// read time

scanf("%lf",&minutes);

// call function

CalcPrintDistance(velocity,minutes);

return 0;

}

Step-by-step explanation:

Read the velocity of vehicle and assign it to variable "velocity".Read the

time traveled by the vehicle and assign it to variable "minutes".Call the

function CalcPrintDistance() with parameter velocity and minutes.This

function will calculate the distance traveled and print it.

Output:

Enter the velocity of vehicle(miles per hour):68.2

Enter the time traveled(in minutes):34.6

Distance traveled by vehicle is:39.33 miles

User Waruyama
by
5.1k points