Lost the will to live!

Hi all,

Thanks so far for all your help you have given me. My latest problem so far I can't seem to get my head around.

Basically I am making a program called "The DeathclocK" which is inspired by those Facebook apps that guess when you are going to die and by what means etc.

The program will be a menu driven console program and so far I have got all the main functions for the menu and a class which will hold information on the user.

However these errors are really frakkn me over and with my limited C++ knowledge I don't know whats going on.

Screenshot!
http://b.imagehost.org/0077/errors.png


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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <string>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <cstdio>

using namespace std;


class user //will store the attributes for the current player of the program
{
private:
	int age;
	int days;
	int months;
	int years;
	bool gender;
	bool drinker;
	bool smoker;
	bool exercise;
	bool diet;

public:

	int getage (int);
	int setage (int, int);
};

//constructor for user class



//destructor



//member functions

int getage (int userage)
{
	cout << "Enter your age in years";
	cin >> userage;
	cout << endl;
	return userage;
}

int setage (int userage, int age)
{
	cout << "Setting class age to equal inputted userage";
	cout << age;
	age = userage;
	cout << age << endl;
	return age;
}


////////////////////////////////////////////////////////////////////////////////////////////////////
// function declarations
void menu1(int); 
void clearscreen();
void openuserlist ();
void start ();


void start ()
{
int age;
int userage;
user newuser;
newuser.getage (userage);
newuser.setage (userage,age);

};


void Clearscreen() //used to clear screen (create 100 blank lines)
{
    cout << string(100,'\n');
	return;
};

////////////////////////////////////////////////////////////////////////////////////////

void menu1(int response) // Function responsible for displaying the main menu
{
	do
	{
		//Menu level 1
		cout << "\t___________________________" << endl;
		cout << "\t1. Calculate your fate" << endl;
		cout << "\t2. See some of fate's victims" << endl;
		cout << "\t3. Settings" << endl;
		cout << "\t___________________________" << endl;
		cout << "\tPlease choose an option [1-3]   ";
		cin >> response;
		//Switch for main menu has 3 options plus a default option 
		switch (response)
		{
			case 1:
				{
					Clearscreen();
					start();
					return;
				}
			case 2:
				{
					Clearscreen();
					openuserlist();
					return;
				}
			case 3:
				{
					Clearscreen();
					return;
				}
			default:
				{
					Clearscreen();
				}
		}
	}
	while (response !=1 && response !=2 && response !=3);
};



////////////////////////////////////////////////////////////////////////////////////////


void openuserlist ()
{
	string name;
	int years;
	string death;
	ifstream previoususers;
		previoususers.open ("dk_previoususers.txt");
		if (previoususers.is_open())
		{
			cout << "Successfully opened file" << endl;
			cout << "___________________________________" << endl;
			cout << "Name	Years-Left	Death by" << endl;
			cout << "___________________________________" << endl;
			while (previoususers.good())
			{
				previoususers >> name >> years >> death;
				cout << name << '\t' << years << "\t\t" << death << endl;
			}
			
		}
		else 
			cout << "Error: Could not open file!" << endl;
	return;
};


/////////////////////////////////////////////////////////////////////////////////////////

int main ()
{
	int response = 0;
	//Welcome message and info
	cout << '\t' << "-------------------------" << endl;
	cout << '\t' << "Welcome to the Deathclock" << endl;
	cout << '\t' << "-------------------------" << endl;
	cout << "\t\t" <<   " .-~~-. " << endl;
	cout << "\t\t" <<	"(_o,,o_)" << endl;  
	cout << "\t\t" <<	"  |||| "  << endl;
	
	menu1(response);
	return 0;
}



Help me cplusplus your my only hope *bends over and inserts holochip into droid*
Last edited on
you have to call voids at the beginning of your program.
1
2
3
4
5
6
7
#include <iostream>
using namespace std;

void one(string &username, int &userage);
void xxx(string &blah);
main()
{one(username, userage);}
The warnings are this:

1
2
3
4
5
int age;   // ????  what is age?
int userage;  // ???? what is userage
user newuser;
newuser.getage (userage);  // ???
newuser.setage (userage,age);  //??? 


You're trying to pass userage and age to functions before you set them to anything, meaning you'll get garbage. What exactly are you setting the age to?


Your errors are because your getage/setage functions are global. Meaning you never gave a body to your user::getage and user::setage functions.

You probably didn't mean to make those functions global:

 
int user::getage()  // this makes more sense 



Also your functions are a little misleading. I would expect 'getage' to simply return the age of the user. Not to do any i/o with the user. But whatever.


EDIT:

re: LittleQuick -- calling voids has nothing to do with anything. Also, main() must always return an int.
Last edited on
So when I put my constructor in this should fix some of the problems?

[Code]
user::user()
{
age;
days;
months;
years;
gender;
drinker;
smoker;
exercise;
diet;
}
[/CODE]
Disch you are correct, very sorry. Totally misread this whole program.
loosebruce:

No, the problem are due to you not giving user::setage and user::getage functions a body. You need to give them a body. The constructor has nothing to do with it

(also that constructor you posted does nothing)


LittleQuick: don't worry about it. ^^
Please forgive my ignorance but I googled "body" and "c++" and I can't seem to understand what you are saying.

I have redone my class and functions and got the errors down to just two.

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
class user //will store the attributes for the current player of the program
{
private:
	int age;
	int days;
	int months;
	int years;

public:
	user::user ();
	int user::getage ();
};

//constructor for user class

user::user ()
{
	int age =0;
	int days =0;
	int months =0;
	int years =0;
}

//destructor



//member functions

int getage (int userage, int age)
{
	age = userage;
	return age;
}



////////////////////////////////////////////////////////////////////////////////////////////////////
// function declarations
void menu1(int); 
void clearscreen();
void openuserlist ();
void start ();


void start ()
{
int age =0;
int userage=0;
cout << "Enter your age in years";
cin >> userage;
cout << endl;
user newuser;
newuser.getage ();

};



The errors are;

Error 1 error LNK2019: unresolved external symbol "public: int __thiscall user::getage(void)" (?getage@user@@QAEHXZ) referenced in function "void __cdecl start(void)" (?start@@YAXXZ) \\ad3\---------\Desktop\Assignment 3\Deathclock\Deathclock\dk_main.obj


Error 2 error LNK1120: 1 unresolved externals \\ad3\----------\Desktop\Assignment 3\Deathclock\Debug\Deathclock.exe 1


-------
I tried looking at the tutorials and see no mention of the term body, could you maybe direct me to a place so I can get my head around this.

Thanks for your patience!

Last edited on
You never seem to implement user::getage(). The only getage() I see is a function that doesn't seem to really do anything at line 30. Did you mean something else? :)

-Albatross
Last edited on
I have figured it out.

I was putting

user::setage (int);

in the function declaration area of the class when i should only have put "setage (int);"

and i have fixed it now when you put this

user::setage (int);

into your function definition area outside the class, which stops the linking error to the class.

thanks c++ forums!
Topic archived. No new replies allowed.