Question

how do i write a program that uses one or more if statements and a loops...

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

Homework Answers

Answer #1

#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:-

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program which: Write a program which uses the following arrays: empID: An array of...
Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to hold each employee’s gross salary....
C++ Write a recursive function that reverses the given input string. No loops allowed, only use...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. I had asked this before but the solution I was given did not work. #include #include using namespace std; void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sammy";    reverse(name);    cout << name << endl; //should display...
How do we reabsorb more water after the PCT? Hint: discuss long Loops of Henle of...
How do we reabsorb more water after the PCT? Hint: discuss long Loops of Henle of the juxtaglomerular nephrons and ADH.
Using C, write a program that will create two child processes with one child process then...
Using C, write a program that will create two child processes with one child process then using “pipe” to send “i love you” to another child process.
How do I solve for the investment in another company?
How do I solve for the investment in another company?
What equations and statements should be used for this problem? Do I select any hypothesis I...
What equations and statements should be used for this problem? Do I select any hypothesis I want? How do I phrase the hypothesis and write the equations? If I have data, what makes the hypothesis true or false? 1) Conduct hypothesis test by comparing monthly average between the two year 2) Within each year, run a appropriate hypothesis comparing June and August.
I understand how to do the problem. What I am confused on is more conceptual. Why...
I understand how to do the problem. What I am confused on is more conceptual. Why is 70.5 the maximum angle? What does it mean when I plug in a smaller angle and get an imaginary answer? Why are larger angles not applicable? A cannon shoots a cannon ball at a launch angle of theta above the horizontal ground with initial speed v_0. (a) Neglecting air resistance, use Newton's second law to find the ball's position as a function of...
SITUATION : Assume that you have to write a program to provide solution to problem face...
SITUATION : Assume that you have to write a program to provide solution to problem face by the company of ABC. The company is providing a service of renting a venue and place such as futsal court, badminton court booking and etc. There are several problems which face by the company in which they have to do it manually. One of the problems maybe during booking of venue. Another problem maybe face by the employee is to reserve the place...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
Write a program in python reverse each and every word of the sentence using function taking...
Write a program in python reverse each and every word of the sentence using function taking string as input parameter from user and passing that string into function and also explain the logic ======================================= input: 'Exam is gonna be good' output: 'maxE si annog eb doog' ================ i am trying like this but getting confused '.'join([w::-1] for w in s.split()]) i need more focus on explanations because it is making me confuse i am not clear with concepts so please...