using functions to convert measurements

I have to write a program that requires the use of four functions, one for the input, two for calculation and one for output of the calculated values.

The purpose of this program is to convert kilograms and grams to pounds and ounces.
The first function is meant to ask the user for their measurement in kilos and grams. Then using two value returning functions to return pounds and ounces.

I'm new to functions so I'm extremely confused and I know my code is a mess and not at all right; nonetheless, here is what I have so far...
**********************************************************************


// 10/5/2016
//convert kilograms and grams to pounds and ounces
//function for input, calculation and output

#include<iostream>
using namespace std;


void conversion(double &kilo, double &grams);
{
void output(double pounds, double ounces);
{


int main()
{
double kilo;
double grams;
double pounds;
double ounces;

cout << "Enter a weight in kilograms: " << endl;
cin >> kilo;

cout << "Enter a weight in grams: " << endl;
cin >> grams;

pounds = kilo*2.2046;
ounces = grams*28.3495;

int conversion(double kilo, double grams);
int output(double pounds, double ounces);

cout<< pounds << " pounds and " << ounces << " ounces " << endl;


return 0;
}
Hello naiuccorle,

Please read http://www.cplusplus.com/forum/beginner/1/
use code tags the <>button to the right of the post window under "format:".
You can edit you post highlight you code and press the <> button.

In the first two line before main that is the way to write a proto type or forward declaration. Although you need to loose the two "{" there are not need here. void conversion needs to be double conversion because the function needs to return the number of pounds. Kilo and grams do not need to be passed as a reference you do not need to change those values in a function.

In the function for ounce conversion pounds should be passed as a reference because you may need to add to pounds.

The calculations for pounds and ounces should be done in functions not in main.

The two lines before the last cout statement are not the way to call a function. the first should be pounds = conversion(kilo, grams);. And then you will need another function to calculate the ounces.

In the function to calculate ounces you will need to consider that ounces could be more than 16 and that you will have to add to pounds.

Hope that helps,

Andy
Topic archived. No new replies allowed.