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....
Please write it in c# program please and if possible no arrays only loops Loop Introduction...
Please write it in c# program please and if possible no arrays only loops Loop Introduction Assignment Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches.   Your function will convert the weight and height into Body Mass Index (BMI). The formula for converting weight into...
In this exercise we will practice using loops to handle collections/containers. Your job is to write...
In this exercise we will practice using loops to handle collections/containers. Your job is to write a program that asks the user to enter a sentence, then it counts and displays the occurrence of each letter. Note: your program should count the letters without regard to case. For example, A and a are counted as the same. Here is a sample run: Enter a sentence: It's a very nice day today! a: 3 times c: 1 times d: 2 times...
How do I convert volume % to volumetric flow rate? This is occurring in a disitillation...
How do I convert volume % to volumetric flow rate? This is occurring in a disitillation column. I have the volume amount poured into the tank, 10L that is 7% methanol. I have a power input of 1.5 kW. I understand the mass balance of a distillation column. What I am confused about is after I found in the distillate, the 1 microliter sample is 5% methanol and 95% water at 5 minutes, how do I conver this to volumetric...
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
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...
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.
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...
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?
Python code only! (Do not include breaks or continue functions) Write a program that asks the...
Python code only! (Do not include breaks or continue functions) Write a program that asks the user to enter the amount that they budgeted for the month. A loop should then prompt the user to enter their expenses, one at a time and to enter 0 to quit. When the loop finishes, the program should display the the amount of budget left. (a negative number indicates the user is over budget and a positive number indicates the user is under...