Many treadmills output the speed of the treadmill in miles per hour (mph) on the console, but most runners think of speed in terms of a pace. A common pace is the number of minutes and seconds per mile instead of mph. Write a program that starts with a quantity in mph and converts the quantity into minutes and seconds per mile. As an example, the proper output for an input of 6.5 mph should be 9 minutes and 13.8 seconds per mile. If you need to convert a double to an int, which will discard any value after the decimal point, then you may use intValue

Respuesta :

Answer:

This question is answered using C++ programming language.

This program does not make use of comments; However, see explanation section for detailed line by line explanation.

The program starts here

#include <iostream>

using namespace std;

int main()

{

 double quantity,seconds;

 int minutes;

 cout<<"Quantity (mph): ";

 cin>>quantity;

 minutes = int(60/quantity);

 cout<<minutes<<" minutes and ";

 seconds = (60/quantity - int(60/quantity))*60;

 printf("%.1f", seconds);

 cout<<" seconds per mile";

 return 0;

}

Explanation:

The following line declares quantity, seconds as double datatype

 double quantity,seconds;

The following line declares minutes as integer datatype

 int minutes;

The following line prompts user for input in miles per hour

 cout<<"Quantity (mph): ";

User input is obtained using the next line

 cin>>quantity;

 

The next line gets the minute equivalent of user input by getting the integer division of 60 by quantity

minutes = int(60/quantity);

The next statement prints the calculated minute equivalent followed by the string " minuted and " without the quotes

 cout<<minutes<<" minutes and ";

After the minutes has been calculated; the following statement gets the remainder part; which is the seconds

 seconds = (60/quantity - int(60/quantity))*60;

The following statements rounds up seconds to 1 decimal place and prints its rounded value

 printf("%.1f", seconds);

The following statement prints "seconds per mile" without the quotes

 cout<<" seconds per mile";

Following are the program to the given question:

Program Explanation:

  • Defining the header file.
  • Defining the main method.
  • Inside the method, three double variables "mph, sec, and min_per_mile", and one integer variable "min" is defined.
  • After defining a variable "mph" is defined that inputs value by user-end.
  • After input value, "sec, min_per_mile, and min" is defined that calculates the value and prints its calculated value.  

Program:

#include<iostream>//header file

using namespace std;

int main()//defining main method

{

   double mph,sec,min_per_mile;//defining a double variable  

int min;//defining integer variable

cout<<"Enter the speed of the treadmill in mph:";//print message

cin>>mph;//input double value

min_per_mile=(1/mph)*60;//defining a double variable that calculates minutes per mile

min=static_cast<int>(min_per_mile);//defining int variable that converts min_per_mile value into integer

sec=(min_per_mile-min)*60;//defining double variable that calculates seconds per mile value  

cout<<"A common pace is the "<<min<<" minutes and "<<sec<<" seconds per mile"<<endl;//print calculated value with message  

return 0;

}

Output:

Please find the attached file.

Learn more:

brainly.com/question/21278031

Ver imagen codiepienagoya