I need help =(
I need help on doing this program. It's for school and I'm stuck and don't know how to code it. This is what I have to do:
Write a program that asks the user for a weight in pounds (lbs) and ounces (oz), and prints out the total weight in pounds and in kilograms. Use the conversion factor of: 1 pound = 16 ounces, and 1 pound = 0.45 kilogram.
When prompting the user for an input value, prompt for a non-space separator between the pounds and ounces. The separator can be a comma, a dash or any reasonable character, as long as its not a space or tab or new line character.
The pounds and ounces must be read in as integer data.
Sample program output:
Enter weight (format: lbs, oz): 10, 15
Weight in lbs: 10.94
Weight in kgs: 4.92
For the program output:
- Print the result with only 2 digits after the decimal point.
- The 2 weights should be in column format, right justified
When calculating the weight, dont forget that the result of the calculation should be floating point number.
This program must be done following this structure chart:
(Try to ignore the ''')
'''''main
''''|
-----------------------
|-----------|-----------|
getInput''''calculate''''printOutput
'''|
''----
''''' |'''|
''topounds''tokilogram
So far I've gotten this:
#include <stdio.h>
int getinput (void)
{
int pound;
int ounces;
char seperator;
printf ("Enter a pound, a seperator, and a ounce: ");
scanf ("%d %c %d", £, &seperator, &ounces);
return;
}
int calculate (int*pound, int*ounces)
{
int founces;
int fpounds;
int kilogram;
founce = (float) ounces;
fpounds = pounds + (founces / 16);
kilogram = fpounds * 0.45f;
return;
}
int printoutput (int*fpounds, *int*kilogram)
{
printf ("weight in lbs: %.2f\n", fpounds);
printf ("Weight in kqs: %.2f", kilogram);
return 0;
}
Please help me out. Thanks.
[2383 byte] By [
nergetic] at [2007-11-19 18:30:04]

# 1 Re: I need help =(
This is not good:
int calculate (int*pound, int*ounces)
{
int founces;
int fpounds;
int kilogram;
founce = (float) ounces;
fpounds = pounds + (founces / 16);
kilogram = fpounds * 0.45f;
return;
}
First, you pass pointers to integers for pounds and ounces and then you don't dereference them.
founce = (float) *ounces;
fpounds = *pounds + (founces / 16);
Second, you don't return a value.
And third the values computed are lost, since they are not returned.
Here is how this functions should look:
void calculate (int pound, int ounces, float& fpounds, float& fkilograms)
{
fpounds = *pounds + (*ounces / 16);
fkilogram = fpounds * 0.45f;
}
Moreover, the printing functions should look like this:
void printoutput (float fpounds, float fkilograms)
{
printf ("weight in lbs: %.2f\n", fpounds);
printf ("Weight in kqs: %.2f\n", fkilograms);
}
And I'll live the main to you...
cilu at 2007-11-10 23:46:38 >

# 2 Re: I need help =(
Don't I need to put:
float fpounds;
float fkilogram;
in void calculate (int pound, int ounces, float& fpounds, float& fkilograms)
Also I thought you need to do:
void calculate (int pound, int ounces, float&fpounds, float&fkilograms)
Since we're giving values for it to calculate with void in front of the calculate means it's not taking in any value with correct? so should it be int calculate and not void calculate?
Lasty are you suppose to leave return; jsut the way it is? Don't you have to return some sort of valuve. My teacher said this is gonna be the hardest Lab to understand and she's correct -____-
Thanks for the help.