how do i write a program that uses one or more if statements and a loops to solve a problem that convert an amount entered to another unit of measure
#include <iostream>
using namespace std;
int main()
{
char ch = 'y';
double m,km;
while(ch=='y')
{
cout<<"Enter the distance in meteres: ";
cin>>m; //Taking meteres from user
if(m<0) //Checking if distance is negative
cout<<"Invalid distance entered";
else{
km = m / 1000; //Converting the distance
cout<<m<<" meteres = "<<km<<" km";
//Printing the ans
}
cout<<"\nDo uou want to continue: ";
cin>>ch; //Taking user's choice
}
return 0;
}
Output:-
Get Answers For Free
Most questions answered within 1 hours.