4. Program that inputs miles from the user and convert miles into kilometers

Chapter 4: 

Input And Output

Programming Exercise

Problem # 4:

Write a program that inputs miles from the user and convert miles into kilometers. One mile is equal to 1.609 kilometer.

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    float miles, kilometers;
    cout<<"Enter miles :"<<endl;
    cin>>miles;
    kilometers = miles/1.609;
    cout<<"Kilometers :"<<kilometers<<endl;
    return 0;
}

Code Screenshot:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

Output:

Chapter 4, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, Input and Output, IT Series, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

Let me know in the comment section if you have any question.

Previous Post:
3. Program to find out the area of triangle when three sides a, b and c of the triangle are given.

Comments

Post a Comment