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....
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Must use loops. Please do not use sequence of if statements. I need it in C++....
Must use loops. Please do not use sequence of if statements. I need it in C++. Given 2 strings, a and b, set result to the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", "aa", and "az" substrings appear in the same place in both strings. for input of "xxcaazz", "xxbaaz" → 3 for input of "abc", "abc" → 2 for input of "abc", "axc" → 0
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.
Coding Exercise: The Great Escape Write a program that prints the following: A double-quote's escaped using...
Coding Exercise: The Great Escape Write a program that prints the following: A double-quote's escaped using a backslash, e.g. \" Note: there is more than one way to do this (as usual)! For example, you could enclose the whole string in single quotes, or in double-quotes. In either case, escaping is needed. For extra practice, solve the problem one way, and then solve it the other way. Can you solve it a third way?
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.
How do I answer and solve this question? Does the problem specify a function with independent...
How do I answer and solve this question? Does the problem specify a function with independent variable x? If so, find the domain of the function. If not, find a value of x to which there corresponds more than one value of y. x2 + y2 = 9
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT