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....
Store Sales in Python Write a program that uses nested for loops to collect sales data...
Store Sales in Python Write a program that uses nested for loops to collect sales data per store and calculate the total and average sales for specified months. The program should first ask for the number of stores and the number of months. After each store iteration it should display the average and total sales for that store. After all iterations, the program should display the total and average sales for all the stores
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...
I learned reinforce the use of If-Else statements and while loops, how to make a project...
I learned reinforce the use of If-Else statements and while loops, how to make a project like sample run1 &2? Please explain in detail thanks. it's Introduction to C Programming use Codeblocks. Sample Run 1 What is the price for supplier #1? 500.49 Is there another supplier to consider? N Supplier #1 had the best price at $500.49. Sample Run 2 What is the price for supplier #1? 250.39 Is there another supplier to consider? Y What is the price...
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
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.
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...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT