18.2k views
0 votes
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;
}

User Jeff Irwin
by
4.1k points

1 Answer

5 votes

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;

}

Step-by-step 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;

}

User CFV
by
4.5k points