Problem in source code

Hi all,
I have a problem with my source code, but I can't find out what I did wrong. Here is the header file (Main.h):

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>

#define CURRDATE 2012

using namespace std;

class Person
{
public:
	int Birthdate;
	int Age(int a, int b)
	{
		return(CURRDATE - Birthdate);
	}
	char Residence[30];
	char FirstName[30];
	char SurName[30];
}Person1, Person2;

void Cls();
void Pause();
void Welcome();
void Input();
void Question();
void CheckAnswers();	

int QuestionAge;

Person * PointerPerson1 = &Person1;
Person * PointerPerson2 = &Person2;

void Cls()
{
	system("cls");

	return;
}

void Pause()
{
	system("pause");

	return;
}

void Welcome()
{
	cout << "Welcome to this database program. You are going to enter the personal data of a person, and then I am gonna check if you can remember that data. Good luck!\n\n";
	
	return;
}

void Input()
{
	cout << "Enter the first name of the person: ";
	cin >> PointerPerson1->FirstName;
	cout << "Enter the surname of the person: ";
	cin >> PointerPerson1->SurName;
	cout << "Enter the year of birth of the person: ";
	cin >> PointerPerson1->Birthdate;
	cout << "Enter the residence of the person: ";
	cin >> PointerPerson1->Residence;

	return;
}

void Question()
{
	cout << "Enter the age of the person: ";
	cin >> QuestionAge;
	cout << "Enter the first name of the person: ";
	cin >> PointerPerson2->FirstName;
	cout << "Enter the residence of the person: ";
	cin >> PointerPerson2->Residence;
	cout << "Enter the surname of the person: ";
	cin >> PointerPerson2->SurName;

	return;
}

void CheckAnswers()
{
	if((QuestionAge == PointerPerson1->Age) && (PointerPerson2->FirstName == PointerPerson1->FirstName) && (PointerPerson2->Residence == PointerPerson2->Residence) && (PointerPerson2->SurName == PointerPerson1->SurName))
		cout << "Very good! You have a good memory!";
	else cout << "Too bad. Try to remember things better.";

	return;
}


And here is the main file (Main.cpp):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <Windows.h>
#include "Main.h"

using namespace std;

int main()
{
	SetConsoleTitle("Database");

	int Choice;
	
	Welcome();	

	Input();	

	Question();	

	CheckAnswers();	

	Pause();
}


Could anyone help?
Thanks in advance!











It would help us a lot if you could post the error(s) or (if it compiles) what you're expecting as output and what you're getting instead. Thank you!

-Albatross
Last edited on
Thanks for the reply!

There are no errors. When it runs, I expect it to first run Welcome(), then the Input(), then the Question() and then the Checkanswers() (these things are defined in the header file). What I get when I compile is: it runs Welcome() and Input() without any problems, then it prompts: Press any key to continue... when I do that, it quits.
I don't know if it is useful, but I use Visual Studio 11 Ultimate Beta
Include your code for main.h, those functions might be breaking things and causing the last functions to be skipped.
There are no errors
1
2
//line 83
if((QuestionAge == PointerPerson1->Age)
does not compile. Age is a method.

Please check out about scope
I can't believe you're not getting errors, lines 36, 43, 64, 78, and 87 are invalid I believe. Also why use a class if you basically only have datatypes in there? I believe a struct would be much easier to use in this case. Otherwise, I have no idea why your code is not reaching question or checkanswers. I'd remove the return statements and see if that helps at all.
lines 36, 43, 64, 78, and 87 are invalid I believe
No, they are not. They are not needed there, but you may want to have another exit point.

I believe a struct would be much easier to use in this case.
A class is the same as an struct.
I know structs and classes are both objects, but is every class a struct? I know every struct can be written as a class, but I thought structs were only public data types.

And having a return in a void function is legal? I get errors all the time saying unexpected return value from void ...(). Maybe it's just warnings, but still.
return; is valid, but completely unnecessary when it isn't used to return from the function prematurely.
The only difference between using class and struct in a class declaration is the default visibility - it's private for class and public for struct.

I know structs and classes are both objects

They aren't objects, they're both classes. Objects are class instances.
Last edited on
Ugh, I was under the impression voids couldn't even use returns, that'll greatly change my coding, and I'll have to read up more on classes and structs now. Especially since C++ 11 released some new things for classes I believe. I need a quick reference guide that simply had code. Maybe I'll make a copy of valid functions and syntax of such and I'll it in as I find more information.
Topic archived. No new replies allowed.