Dremendo Tag Line

Calculate speed in C++

cin - Question 20

In this question, we will see how to input distance in kilometer, time in minutes in C++ programming using the cin statement and find the speed. To know more about cin statement click on the cin statement lesson.

Q20) Write a program in C++ to input distance in kilometer, time in minutes and find the speed.

Formula: Speed = Distance / Time

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int d,t;
    float s;
    cout<<"Enter distance in km ";
    cin>>d;
    cout<<"Enter time in minutes ";
    cin>>t;
    s=d/(float)t;
    cout<<"Speed = "<<s<<" km per minute";
    return 0;
}

Output

Enter distance in km 70
Enter time in minutes 50
Speed = 1.4 km per minute
video-poster