Question

In: Computer Science

a C++ program that reads in weight in pounds and outputs the equivalent length in Kilograms...

a C++ program that reads in weight in pounds and outputs the equivalent length in Kilograms and grams. Use at least three functions: one for input, one or more for calculating, and one for output. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. 1 pound (lb) is equal to 0.45359237 kilograms (kg). There are 1000 grams in a kilogram and 16 ounces in a pound. Its important that (lets the user repeat this computation for new input values until the user says he or she wants to end the program)!!

Solutions

Expert Solution

Program:

#include <iostream>

using namespace std;

int getInput() { // This method helps to take the input from user
    int poundWeight;
    // Take weight as input from user in pounds.
    // Enter -1 to exit
    cout << "Enter -1 to exit" << endl;
    cout << "Enter weight in pounds : ";
    cin >> poundWeight;
    return poundWeight;
}

// This method returns weight in Kilograms for given pounds
float calculateWeight(int poundWeight) {
    float weightInKilos = poundWeight * 0.45359237;
    return weightInKilos;
} 

void getOutput(int poundWeight) {
    float weightInKilos = calculateWeight(poundWeight);
    // Calculate weight in grams for the given Kilograms
    float weightInGrams = weightInKilos * 1000;
    // Printing output
    cout << "Weight in Kilograms : " << weightInKilos << " Kilos"<< endl;
    cout << "Weight in Grams : " << weightInGrams << " grams" << endl;
}

int main()
{
    // Taking input from user
    int inputWeight = getInput();
    // Checking condition to exit the loop
    while(inputWeight != -1) {
        getOutput(inputWeight);
        inputWeight = getInput();
    }
    return 0;
}

Output:


Related Solutions

a C++ program that reads in weight in pounds and outputs the equivalent length in Kilograms...
a C++ program that reads in weight in pounds and outputs the equivalent length in Kilograms and grams. Use at least three functions: one for input, one or more for calculating, and one for output. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. 1 pound (lb) is equal to 0.45359237 kilograms (kg). There are 1000 grams in a kilogram, and 16 ounces...
2. Write a C++ program that; Takes in the weight of a person in Kilograms, converts...
2. Write a C++ program that; Takes in the weight of a person in Kilograms, converts and outputs the equivalent weight in pounds. Format your output to 3 decimal places. Your output should look like this 53.000 Kg is equivalent to 123.459 Ibs (Note 1Kg = 2.2046226218488 lbs) Takes in the price of an item on an online store in pound sterling, converts and outputs the equivalent price in U.S dollars. Format your output to 2 decimal places. Your output...
Write the programs in JavaScript: Write a program that reads a text file and outputs the...
Write the programs in JavaScript: Write a program that reads a text file and outputs the text file with line numbers at the beginning of each line.
Express your weight in the units of pounds and newtons, and your mass in the units of slugs and kilograms.
Express your weight in the units of pounds and newtons, and your mass in the units of slugs and kilograms.
You need to write a program that reads in two integers from cin and outputs an...
You need to write a program that reads in two integers from cin and outputs an horribly inefficent calculation of the median value. First count from the first number to the second, but stop one short. Then, count from that number back towards the first, again stopping one short. Continue until you reach a single number. Enter 3 and 9 solution: 3456789 987654 45678 8765 567 76 6
USING MATLAB: Create a BMI calculator application that reads the user’s weight in pounds and height...
USING MATLAB: Create a BMI calculator application that reads the user’s weight in pounds and height in inches (or, if you prefer, the user’s weight in kilograms and height in meters), then calculates and displays the user’s body mass index. Also, the application should display the following information from the Department of Health and Human Services/National Institutes of Health so the user can evaluate his/her BMI: BMI VALUES ("Underweight : Less than 18.5 Normal : between 18.5 and 24.9 Overweight...
Write a program that reads in the radius and length of a cylinder and computes volume...
Write a program that reads in the radius and length of a cylinder and computes volume using the following formulas: area = radius * radius * PI volume = area * length
write a program on c++ that outputs a calendar for a given month in a given...
write a program on c++ that outputs a calendar for a given month in a given year, given the day of the week on which the 1st of the month was. The information in numeric format (months are: 1=Januay, 2=February 3=March, 4= April, 5= May, 6= June, 7= July... etc days are 1=Sunday, 2=Monday, 3= Tuesday, 4= Wednesday, 5= Thursday, 6= Friday and 7= Saturday ). The program output that month’s calendar, followed by a sentence indicating on which day...
Language C++ Ask the user to enter their weight (in pounds) and their height in inches....
Language C++ Ask the user to enter their weight (in pounds) and their height in inches. Calculate their Body Mass Index (BMI) and tell them whether they are underweight, overweight, or at optimal weight. BMI formula: weight * 703 / (height * height) Optimal weight is a BMI from 19 to 26. Lower is underweight, higher is overweight. Prompts: Enter your weight (in pounds): [possible user input: 144] Enter your height (in inches): [posible user input: 73] Possible Outputs: Your...
C Programming Write a program in C that reads in a file, stores its contents as...
C Programming Write a program in C that reads in a file, stores its contents as a character array/pointer (char*) into an unsigned character array/pointer (unsigned char* message). Note: the input file can have one line or multiple lines and vary in length
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT