Hi everyone, I'm new to the forums, as you can probably tell by my join date. I am currently stuck on a homework assignment that I am working on and any help in the right direction would be appreciated. OK so my hw assignment calls for me to take in a user's inputs of pounds and ounces and convert them into kilograms and grams. The second part of the problem (which is what i'm having trouble with) is that is wants us to use at least three functions to do it. one for input, one for calculation and one for output. I can only get this far:
//This program takes in a user's input of pounds and ounces and converts
//The input to kilograms and grams
void introduction();
//Postcondition: Description of program is written on the screen
void input(double& num1, double& num2);
//Precondition: User is ready to enter values
//Postcondition: The values will be stored and used in the calculation function
void calculation(double& num1, double& num2);
//Precondition: Converts the user's numbers from pounds and ounces
//to kilograms and grams
void output(double num1, double num2);
//Outputs the calaculation
void introduction()
{
using namespace std;
cout << "This program is designed to take in the weight of pounds and ounces\n"
<< "and convert them to kilograms and grams." << endl;
}
void input(double& pounds, double& ounces)
{
using namespace std;
cout << "Please enter the number of pounds in an item.\n";
cin >> pounds;
cout << "Please enter the number of ounces in an item.\n";
cin >> ounces;
}
I am aware that my conversions are wrong but I can change that later. What I'm having trouble with is making another function for the calculation and using it part of my output, instead of having my calculation part of my output function.
I don't understand how i would get the two new variables i create (kilogram,grams) in a calculations function to to be part of the output function. I'm sure it's a simple fix but i'm having trouble figuring it out. Any push in the right direction would be very helpful
I think you'll need to make your calculation function take four parameters; something like this: void calculate(double pounds, double ounces, double& kilograms, double& grams);
Pass to the function your input data as the first to parameters, and have the output data be stored in the second two.
Thank you zhuge you were right. Your reply just saved me some time, been working on it for like 2 hours and could not figure it out. I'm not quite done with the assignment so i might need help down the road but thanks again for your reply