#include <iostream>
#define CURRDATE 2012
usingnamespace 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;
}
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 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.
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.
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.