Problems with tutorial program

Hello all,

I've been going through the c++ tutorial and got to the point with classes. After reading the text, I look at the program examples and then try to program something similar. However, I constantly get errors eventhough it looks perfectly legit to me.
The simple program asks for user input of money, price and quantity and just calculates how many of that item can be purchased.

Here is the code:
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
#include <iostream>


using namespace std;


class properties {
private: int x, y, z;
public:
	void initialize_values (int, int, int);
	int calculate ();
}

void properties::initialize_values (int money, int price, int num)
{
	x = money;
	y = price;
	z = num;
}

int properties::calculate () 
{
	int total;
	total = z*y;
	return (x/total);

}

int main ()
{
	int a,b,c;
	properties test;
	cin >> a;
	cin >> b;
	cin >> c;
	test.initialize_values(a, b, c);
	cout << test.calculate() << endl;
	system("pause");
	return 0;
}


The error I get are in german, but I'll try to translate:

'properties' followed by void not allowed (forgot semikolon?)
'properties properties:: initialize_values(int,int,int)' Overloaded funktion differentiates only by back type of ' void properties::initizalize_values(int,int,int)'
'properties::initialize_values': Neu definition, different basic types.
'properties::initialize_values' Error in the functiondefinition or function declaration, funktion not called.

This is weird to me, seeing as the tutorial code is following and works without problems:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
class CRectangle {
int x, y;
public:
void set_values (int,int);
int area () {return (x*y);}
};
void CRectangle::set_values (int a, int b) {
x = a;
y = b;
}
int main () {
CRectangle rect, rectb;
rect.set_values (3,4);
rectb.set_values (5,6);
cout << "rect area: " << rect.area() << endl;
cout << "rectb area: " << rectb.area() << endl;
return 0;
}


Can anyone see the mistake? Thanks!
Last edited on
You need a semicolon after the closing brace for your class.
Oh...thanks mate! And I just realized my program makes no sense lol.
Last edited on
Topic archived. No new replies allowed.