Posted by Jeffry on Monday, November 29, 2010 at 6:30am.
If you have a problem coding, post your code, we'll help you debug syntax or logic errors.
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.
double 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;
}
double convertToGrams(double pounds, double ounces, double kilograms, double grams)
{
kilograms = pounds / 2.2046;
kilograms = floor(kilograms); // extract just entire portion of kg
grams = (kilograms )*1000; // the substraction will be remaining grams
return kilograms;
return grams;
}
void giveOutput(double kilograms, double grams)
{
cout << "The object weighs " << kilograms << " kilograms and " << grams << " grams\n";
}
Related Questions
Programming - Write a program to do the following: In main, declare a Player ...
college - Write a C++ program to fill an array with 6 numbers, and then reverse...
pseudocode - Assume that your family has 10 members. Assume further that each ...
programming - John: 50,000 Joe: 30,000 Jane: 60,000 Jill: 25,000 Total: 165,000 ...
Pseudocode with sequential, selection and arrays - Analyze, design, and document...
computer science - Declare a structure whose tag name is Emp and that contains ...
Programming - Here is the question that I need help to write the code for the ...
programming - How to write a program to create a class roster using an array? ...
computer programming c++ - write a program that can read 10 interger values into...
computer programming - write a program that can read 10 interger values into an ...
For Further Reading