Function output errors

So I wrote this code so that, given some user inputs, would output how long it would take to mow a lawn. I originally had 'timetaken' as a function, but it was outputting a number that looked hexadecimal in format in the dubugging stage.

I have since changed timetaken to a simple equation, and put 'housearea' and 'gardenarea' as functions (since I have to include at least one for this assignment). The problem is, now both housearea and gardenarea are outputting hexadecimal-esque numbers, but timetaken is fine. Am I doing something weird with my functions which is causing this to happen? Thanks in advance.

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
#include <iostream>
using namespace std;

int gardenarea(int length, int width)
{
	int ga;
		ga = length * width;
		return ga;
}

int housearea(int side)
{
	int ha;
	ha = side * side;
	return ha;
}

int main()
{
	int length, width, side, mowingrate, timetaken;
	cout << "Please enter length of garden in metres. " << endl;
	cin >> length;
	cout << "Please enter width of garden in metres. " << endl;
	cin >> width;
	gardenarea(length, width);
	cout << "Area of garden is " << gardenarea << " m^2." << endl;

	cout << "Please enter length of side of house in metres. " << endl;
	cin >> side;
	housearea(side);
	cout << "Area of house is " << housearea << "m^2." << endl;

	cout << "Please enter mowing rate, assuming the mowing rate unit is square metres per minute. " << endl;
	cin >> mowingrate;

	timetaken = gardenarea(length,width) - housearea(side) / mowingrate;
	cout << "Time taken to mow garden is " << timetaken << " minutes." << endl;
	return 0;
}
Last edited on
This is wrong:
30
31
	housearea(side);
	cout << "Area of house is " << housearea << "m^2." << endl;
Consider instead one of the two options below:
30
31
	//
	cout << "Area of house is " << housearea(side) << "m^2." << endl;
30
31
	int area = housearea(side);
	cout << "Area of house is " << area << "m^2." << endl;
Similar for lines 25/26 and 36/37
Last edited on
That has worked amazingly - I now see where I was going wrong. Thank you!
Topic archived. No new replies allowed.