C++

How to write a program that converts miles per hour to feet per second.
What are you having trouble with?
This is as far as I got.

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;
int main()

{
	int mile_per_hour ;
	int feet_per_second;
	
	cout << "Enter the number of miles 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

main()
{
	int mph,fps;
	
	std::cout<<"MPH -> FPS"<<std::endl<<std::endl;
	std::cout<<"MPH?  ";
	std::cin>>mph;
	fps=mph*22/15;
	std::cout<<"FPS = "<<fps;
}

/*  m       5280       f
 * ---  x  ------  =  ---
 *  h       3600       s
 */
Last edited on
Would this work?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
int main()

{
	
	int miles;
	int miles_per_hour ;
	int feet_per_second;
	
	cout << "Enter the number of miles. ";
	cin >> miles;
	miles_per_hour= miles/60;
	cout << "The number ofmiles per hour is " << miles_per_hour << endl;
	
	feet_per_second = miles_per_hour * 1.46667;
	cout << "The number of feet per second is " << feet_per_second << endl;
	
	return 0;
}
Enter the number of miles. 10
The number ofmiles per hour is 0
The number of feet per second is 0


Consider this:

1
2
int a=5, b=100, c;
c=a/b;

5/100 is 0.05, which is type float, but is truncated because it is being assigned to type int. Apply this problem to yours and change your code based on it.
Topic archived. No new replies allowed.