# Convert pounds and ounces to kilograms and grams.

Write a program that reads in a weight in pounds and ounces and putputs the equivalent weight in kilograms and grams.  Use at least three functions: one for input, one or more for calculating, and one for output.  Inlcude 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. There are 2.2046 pounds in a kilogram, 1000 grams in a kilogram, and 16 ounces in a pound.

#include <iostream>
using namespace std;

const double poundsPerKilogram = 2.2046;
const int ouncesPerPound = 16;
const int gramsPerKilogram = 1000;

void getInput(double& pounds, double& ounces);
// Precondition: User is ready to enter values correctly.
// Postcondition: The values of pounds and ounces have been set to the weight
// of the object.

void convertToGrams(double poundss, double ounces, double& kilograms, double& grams);
// Precondition: User is ready to enter values correctly.
// Postcondition: The values of kilograms and grams have been set to

void giveOutput(double kilograms, double grams);
// Precondition: The weight of the object is stored in kilograms and grams.
// Postcondition: The values of kilograms and grams have been written to the screen.

int main()
{
double pounds, ounces, kilograms, grams;
char ans;

do
{

getInput(pounds, ounces);
convertToGrams(kilograms, grams, pounds, ounces);
giveOutput(kilograms, grams);

cout << "Do you want to do another calculation?\n"
<< "Press y for yes, n for no,\n"
<< "and then press return: ";
cin >> ans;
cout << endl;

} while (ans == 'y' || ans == 'Y');

return 0;
}

void getInput(double& pounds, double& ounces)
{
cout << "Enter the weight of the object in pounds and ounces\n";
cout << "pounds: ";
cin >> pounds;
cout << "ounces: ";
cin >>ounces;
}

void convertToGrams(double pounds, double ounces, double& kilograms, double& grams)
{
return (pounds/2.2046)

void giveOutput(double kilograms, double grams)
{
cout.setf(ios::fixed);
cout.precision(0);
cout << "The object weighs " << kilograms << " kilograms and " << grams << " grams\n";
}

I cant continue with the code in function   void convertToGrams, can someone help????
###### Who is Participating?

Software ArchitectCommented:
convertToGrams must not return a value since is declared as void. Put result into kilograms and grams variables instead.
Also will be useful the floor() function, you will require to include the "math.h" header file

void convertToGrams(double pounds, double ounces, double& kilograms, double& grams)
{
double total kg = return pounds / 2.2046;
kilograms = floor(kg);   // extract just entire portion of kg
grams = (kg - kilograms)*1000;    // the substraction will be remaining grams
}

0

Author Commented:
{
double kg;
double total kg = return pounds / 2.2046;
kilograms = floor(kg);   // extract just entire portion of kg
grams = (kg - kilograms)*1000;    // the substraction will be remaining grams
}

when i put this into my program it shown that Parse Error before =, what does that mean???
0

Software ArchitectCommented:
There is a typo in my code:
double total kg = return pounds / 2.2046;
must be:
double kg = pounds / 2.2046;
0

Author Commented:
But with your code, it doesnt give out the output.
0

Software ArchitectCommented:
No, it doesn't prints the output, just return kilograms and grams in passed variables.
You have to make a function for that.
0

Commented:
can you please post the full length vesrion with output for this program please?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.