height conversion function prob

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <iomanip>
#include <conio.h>		//for _getch()

using namespace std;

const double CM_PER_INCH = 2.54;				// othere are 2.54 cm in one inch
const int INCH_PER_FOOT = 12;					// there are 12 inches in one foot

int getHeight();
int myHeight;
void convert(int, int, int);
void displayResult(int, int, int);

int main()
{
	int myHeight = 0;
	int feet = 0, 
	inches = 0;

	getHeight();

	convert(myHeight, feet, inches);

	displayResult(myHeight, feet, inches);	
	
	_getch();	//to preserve output screen
	return 0;
}

int getHeight()
{
	cout << "Enter your height in centimeter: ";	
	cin >> myHeight;			

	return myHeight;
}

void convert(int myHeight, int feet, int inches)
{
	int totalInch = static_cast<int>(myHeight / CM_PER_INCH + 0.5);				

	feet = totalInch / INCH_PER_FOOT;	
	inches = totalInch % INCH_PER_FOOT;
}

void displayResult(int cm, int feet, int inches)
{
	cout << fixed << showpoint << setprecision(1);

	cout << endl << myHeight << " centimeter is equivalent to:\n"
		 << feet << " feet and "
	     << inches << " inch\n";
}
Last edited on
added code tags and changed it a bit. Keep getting variables used without being initialized.
Doing something wrong still.
Last edited on
The variables myHeight, feet, and intInch does not have any value. Give them values to be able to use them in your function.

I.e
1
2
3
myHeight = 6;
feet = 60;
intInch = 3;
Last edited on
Lines 16, 17, and 18: you declare 3 variables and don't initialize them, exactly as the compiler is probably telling you.
16
17
18
int myHeight = 0;
int feet = 0; 
int inch = 0;


Also, lines 17 and 18 aren't doing what you think they're doing. You're actually declaring 2 ints, one named feet, the other name intInch. I think you meant to say it the way I have it in my example above. Line 17 ending with a semicolon and line 18 actually declaring an int variable named inch.
Last edited on
I should have said that the problem is in how i'm declaring or calling something. Because i get to the results and it shows
x centimeters is equal to
0 feet 0 inches
You're using the global variable int myHeight; and then selectively hiding it by redeclaring it in some of your functions. You don't need global data for this. Remove line 11.
Still doesnt help with the convert section. It doesnt convert centimeters to feet and inches and i don't know why.

had someone else help me find what was actually wrong.
Last edited on
Topic archived. No new replies allowed.