A pedometer treats walking 2,000 steps as walking 1 mile. Write a program whose input is the number of steps, and whose output is the miles walked.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows:
printf("%0.2lf", yourValue);
Ex: If the input is:
5345
the output is:
2.67
Your program must define and call a function:
double StepsToMiles(int userSteps)
#include
/* Define your function here */
int main(void) {
/* Type your code here. */
return 0;
}

Respuesta :

Answer:

The complete program is:

#include <stdio.h>

double StepsToMiles(int userSteps){

   return userSteps/2000.00;

}

int main(void) {

   int userSteps;

   printf("User Steps: ");

   scanf("%d",&userSteps);

   printf("%0.2f", StepsToMiles(userSteps));

   return 0;

}

Explanation:

This line defines the function

double StepsToMiles(int userSteps){

This returns the required output by dividing userSteps by 2000.

We used 2000.00 because we want it to return a floating point number

   return userSteps/2000.00;

}

The main begins here

int main(void) {

This declares userSteps as integer

   int userSteps;

This prompt user for input

   printf("User Steps: ");

This gets user input

   scanf("%d",&userSteps);

This calls the function and also returns the required output to 2 decimal places

   printf("%0.2f", StepsToMiles(userSteps));

   return 0;

}

Answer:

Coral Language Code

A pedometer treats walking 2,000 steps as walking 1 mile. Define a function named StepsToMiles that takes an integer as a parameter, representing the number of steps, and returns a float that represents the number of miles walked. Then, write a main program that reads the number of steps as an input, calls function StepsToMiles() with the input as an argument, and outputs the miles walked.

Output the result with four digits after the decimal point, which can be achieved as follows:

Put result to output with 4 decimal places

If the input of the program is:

5345

the function returns and the output of the program is:

2.6725

Your program should define and call a function:

Function StepsToMiles(integer userSteps) returns float numMiles

Explanation:

Function StepsToMiles(integer userSteps) returns float numMiles

  numMiles = userSteps / 2000.0

 

Function Main() returns nothing

  float result

  integer userSteps

  userSteps = Get next input

  result = StepsToMiles(userSteps)

  Put result to output with 4 decimal places

ACCESS MORE