SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
C++ Basics
Exercise:
Programming Projects
Question:13 | ISBN:9780321531346 | Edition: 7

Question

13. 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. (Continued)

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

//Header file section
 #include<iostream>
using namespace std;

int main()
{
    double mph;
	cout<<"Enter the speed of the treadmill in mph:";
	cin>>mph;
	double min_per_mile=(1/mph)*60;
	int min=static_cast<int>(min_per_mile);
	double sec=(min_per_mile-min)*60;
	cout<<"A common pace is the "<<min<<" minutes and "<<sec
                          <<" seconds per mile"<<endl;
	return 0;
}

OUTPUT OF THE PROGRAM CODE:

Enter the speed of the treadmill in mph:6.5
A common pace is the 9 minutes and 13.8462 seconds per mile

 

0 0

Discussions

Post the discussion to improve the above solution.