compile errors in linux

I wrote this program in visual C++ but it has to be able to compile in linux.... Im getting many errors and im not sure what they mean or how to fix them....any help would be greatly appreciated
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
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <ctime>
#include <sstream>

using namespace std;

class Character
{
public:
	Character(void);
	int getIntelligence();
	void setLoseIntelligence();
	void setGainIntelligence();
	void setRandomIntelligence();
	int getTime();
	void setTime();
	double getMoney();
	void setPlusMoney();
	void setMinusMoney();
	void setRandomMoney();
	int getLocation();
	void setLocation();
	void outputCharacter();
	void setRandomTime();
	int getScore();
	int Score();
	bool checkAttributes();
	


private:
	int intelligence;
	int time;
	int location;
	double money;
	int score;
	
	
};




the errors i am getting are

jwh0003_1.cpp: In member function 'void System::moveForward()':
jwh0003_1.cpp:158: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void System::quit()':
jwh0003_1.cpp:219: error: 'exit' was not declared in this scope
jwh0003_1.cpp: In function 'int main()':
jwh0003_1.cpp:224: error: 'srand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Menu::output()':
jwh0003_1.cpp:298: error: 'system' was not declared in this scope
jwh0003_1.cpp:309: error: 'exit' was not declared in this scope
jwh0003_1.cpp: In constructor 'Character::Character()':
jwh0003_1.cpp:319: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Character::setRandomIntelligence()':
jwh0003_1.cpp:343: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Character::setRandomTime()':
jwh0003_1.cpp:358: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Character::setRandomMoney()':
jwh0003_1.cpp:378: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'bool Character::checkAttributes()':
jwh0003_1.cpp:412: error: 'system' was not declared in this scope
jwh0003_1.cpp:418: error: 'system' was not declared in this scope
jwh0003_1.cpp:424: error: 'system' was not declared in this scope
jwh0003_1.cpp:430: error: 'system' was not declared in this scope
jwh0003_1.cpp: In member function 'void Encounter::puzzles()':
jwh0003_1.cpp:450: error: 'rand' was not declared in this scope
jwh0003@tux196:~$ jwh0003@tux196:~$ g++ jwh0003_1.cpp -o game
jwh0003_1.cpp: In member function 'void System::moveForward()':
jwh0003_1.cpp:158: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void System::quit()':
jwh0003_1.cpp:219: error: 'exit' was not declared in this scope
jwh0003_1.cpp: In function 'int main()':
jwh0003_1.cpp:224: error: 'srand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Menu::output()':
jwh0003_1.cpp:298: error: 'system' was not declared in this scope
jwh0003_1.cpp:309: error: 'exit' was not declared in this scope
jwh0003_1.cpp: In constructor 'Character::Character()':
jwh0003_1.cpp:319: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Character::setRandomIntelligence()':
jwh0003_1.cpp:343: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Character::setRandomTime()':
jwh0003_1.cpp:358: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Character::setRandomMoney()':
jwh0003_1.cpp:378: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'bool Character::checkAttributes()':
jwh0003_1.cpp:412: error: 'system' was not declared in this scope
jwh0003_1.cpp:418: error: 'system' was not declared in this scope
jwh0003_1.cpp:424: error: 'system' was not declared in this scope
jwh0003_1.cpp:430: error: 'system' was not declared in this scope
jwh0003_1.cpp: In member function 'void Encounter::puzzles()':
jwh0003_1.cpp:450: error: 'rand' was not declared in this scope
-bash: jwh0003@tux196:~$: command not found
jwh0003@tux196:~$ jwh0003_1.cpp: In member function 'void System::moveForward()':
-bash: jwh0003_1.cpp:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:158: error: 'rand' was not declared in this scope
-bash: jwh0003_1.cpp:158:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp: In member function 'void System::quit()':
-bash: jwh0003_1.cpp:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:219: error: 'exit' was not declared in this scope
-bash: jwh0003_1.cpp:219:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp: In function 'int main()':
-bash: jwh0003_1.cpp:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:224: error: 'srand' was not declared in this scope
-bash: jwh0003_1.cpp:224:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp: In member function 'void Menu::output()':
-bash: jwh0003_1.cpp:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:298: error: 'system' was not declared in this scope
-bash: jwh0003_1.cpp:298:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:309: error: 'exit' was not declared in this scope
-bash: jwh0003_1.cpp:309:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp: In constructor 'Character::Character()':
-bash: jwh0003_1.cpp:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:319: error: 'rand' was not declared in this scope
-bash: jwh0003_1.cpp:319:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp: In member function 'void Character::setRandomIntelligence()':
-bash: jwh0003_1.cpp:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:343: error: 'rand' was not declared in this scope
-bash: jwh0003_1.cpp:343:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp: In member function 'void Character::setRandomTime()':
-bash: jwh0003_1.cpp:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:358: error: 'rand' was not declared in this scope
-bash: jwh0003_1.cpp:358:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp: In member function 'void Character::setRandomMoney()':
-bash: jwh0003_1.cpp:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:378: error: 'rand' was not declared in this scope
-bash: jwh0003_1.cpp:378:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp: In member function 'bool Character::checkAttributes()':
-bash: jwh0003_1.cpp:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:412: error: 'system' was not declared in this scope
-bash: jwh0003_1.cpp:412:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:418: error: 'system' was not declared in this scope
-bash: jwh0003_1.cpp:418:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:424: error: 'system' was not declared in this scope
-bash: jwh0003_1.cpp:424:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:430: error: 'system' was not declared in this scope
-bash: jwh0003_1.cpp:430:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp: In member function 'void Encounter::puzzles()':
-bash: jwh0003_1.cpp:: command not found
jwh0003@tux196:~$ jwh0003_1.cpp:450: error: 'rand' was not declared in this scope
-bash: jwh0003_1.cpp:450:: command not found
jwh0003@tux196:~$ clear
jwh0003@tux196:~$ g++ jwh0003_1.cpp -o game jwh0003_1.cpp: In member function 'void System::moveForward()':
jwh0003_1.cpp:158: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void System::quit()':
jwh0003_1.cpp:219: error: 'exit' was not declared in this scope
jwh0003_1.cpp: In function 'int main()':
jwh0003_1.cpp:224: error: 'srand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Menu::output()':
jwh0003_1.cpp:298: error: 'system' was not declared in this scope
jwh0003_1.cpp:309: error: 'exit' was not declared in this scope
jwh0003_1.cpp: In constructor 'Character::Character()':
jwh0003_1.cpp:319: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Character::setRandomIntelligence()':
jwh0003_1.cpp:343: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Character::setRandomTime()':
jwh0003_1.cpp:358: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'void Character::setRandomMoney()':
jwh0003_1.cpp:378: error: 'rand' was not declared in this scope
jwh0003_1.cpp: In member function 'bool Character::checkAttributes()':
jwh0003_1.cpp:412: error: 'system' was not declared in this scope
jwh0003_1.cpp:418: error: 'system' was not declared in this scope
jwh0003_1.cpp:424: error: 'system' was not declared in this scope
jwh0003_1.cpp:430: error: 'system' was not declared in this scope
jwh0003_1.cpp: In member function 'void Encounter::puzzles()':
jwh0003_1.cpp:450: error: 'rand' was not declared in this scope
the code is too long so its in segments.....

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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
class System
{
public:
	void gameMenu(string username);
	void moveForward();
	void readPapers();
	void looseChange();
	void viewChar();
	void quit();
	void Scores();
	

private:
	Character character;

	
};

class Menu
{
      public:
             string choice;
             void output();      
      };

class Encounter
{
public:
	void nothingHappens();
	void puzzles();
	void encounterProfessor();
	void encounterStudent();
	void attacked();
	void gradePapers();
	Encounter(Character* charac);

private:
	Character *character;
	

};

class HighScores
{
public:
	void readScores();
	void writeScores();
	void scoresOut();
	//here
	int addScore(string username, int highScore);
	//here
	void inputScore(string username, int highScore);
	vector < pair < string, int > > v;
};

void System::gameMenu(string username)
{
	
	viewChar();
	
	string menuChoice;
	while (menuChoice != "5")
	{
		
	cout << "\n1) Move forward (takes time, could be risky...) " << endl;
	cout << "2) Read technical papers (boost intelligence, takes time) " << endl;
	cout << "3) Search for loose change (boost money, takes time) " << endl;
	cout << "4) View Character " << endl;
	cout << "5) Quit the game " << endl;
	cout << "Please choose an action: ";
	
	cin >> menuChoice;
	

	if(menuChoice == "1")
	{		
	moveForward();
	}

	else if(menuChoice == "2")
	{
	readPapers();
	}

	else if(menuChoice == "3")
	{
		looseChange();
	}

	else if(menuChoice == "4")
	{
		viewChar();
	}

	else if(menuChoice == "5")
	{
		quit();
	}

	if (character.checkAttributes() == true)
	{
		HighScores scorez;
		scorez.addScore(username, character.getScore());
			return;
	}
}
}

//idea on how to do percentages from someone on Yahoo Answers http://answers.yahoo.com/question/index?qid=20090924083620AADsumy
void System::moveForward()
{
	character.setLocation();
	Encounter encounter(&character);
	cout << "\nYou chose to move forward and ";
	int random = (rand()%100);

	if (random <= 30)
	{
	cout << "nothing happened!" << endl;
	encounter.nothingHappens();
	character.setTime();
	}

	else if(random <= 55)
	{
		cout << "you encountered a puzzle!" << endl;
		encounter.puzzles();
		character.setTime();
	}

	else if(random <= 70)
	{
		cout << "you were attacked!" << endl;
		encounter.attacked();
	}

	else if(random <= 80)
	{
		cout << "you encountered a professor." << endl;
		encounter.encounterProfessor();
	}

	else if(random <= 90)
	{
		cout << "you encountered another student." << endl;
		encounter.encounterStudent();
	}

	else if(random <= 100)
	{
		cout <<"you are forced to grade papers." << endl;
		encounter.gradePapers();
	}
}

	void System::readPapers()
	{
	character.setTime();
	character.setRandomIntelligence();
	}

	void System::looseChange()
	{
		character.setTime();
		character.setRandomMoney();

	}

	void System::viewChar()
	{
	character.outputCharacter();
	}

	void System::quit()
	{
	exit(1);
	}

int main()
{
	srand((unsigned)time(0));
    cout <<"What's your username? ";
    string username;
//Found getline() at http://www.cppreference.com/wiki/string/start
	getline(cin, username);
cout << "===========================================================" << endl;
    cout << "|                  Welcome, " << username << "!                        |" << endl;
    cout << "===========================================================" << endl;
    cout << "" << endl;
    
	Menu userChoice;
	userChoice.output();
       
	
}

void Menu::output()
{
	string username = "";
	while(choice != "3"){
	
    cout << "1) Start a New Game of Dunstan and Dragons!" << endl;
    cout << "2) View top 10 High Scores" << endl;
    cout << "3) Quit Game and Get a Life" << endl;
    cout << "Please choose an option: ";
    cin  >> choice;
     
	
           if(choice == "1")
		   {
				System menu;
				menu.gameMenu(username);
				system("PAUSE");
		   }

		   else if(choice == "2"){
               HighScores highScore;
			   cout << "\n Top 10 High Scores " << endl;
			   highScore.scoresOut();
			   cout <<""<<endl;
		   }
		   else if(choice == "3")
		   {
			   exit(1);
		   }   

		 
	}	
}
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
Character::Character()
{	
	//Got help on the random number generator from http://www.daniweb.com/forums/thread1769.html# 
    	intelligence = (rand()%18)+8;
        time = (rand()%18)+8;     
        money =((rand()%1800)+(double)800)/(double)100; 
		location = 20;
}

int Character::getIntelligence()
{
	return intelligence;
}

void Character::setLoseIntelligence()
{
	intelligence = intelligence - 3;

}

void Character::setGainIntelligence()
{
intelligence = intelligence + 2;
}

void Character::setRandomIntelligence()
{
intelligence = (intelligence + (rand()%5)+1);
}

int Character::getTime()
{
return time;
}

void Character::setTime()
{
time = time + 10;
}

void Character :: setRandomTime()
{
time = (time - ((rand()%5)+1));
}

double Character :: getMoney()
{
return money;
}

void Character :: setPlusMoney()
{
	money = money + 10.00;
}

void Character :: setMinusMoney()
{
money = money - 20.00;
}

void Character :: setRandomMoney()
{
	money = (money + (rand()%5)+1);
}

int Character::getLocation()
{
	return location;
}

void Character::setLocation()
{
    location = (location - 1);
}

int Character::getScore()
{
return score;
}

void Character::outputCharacter()
{
	cout << "\nYou have: " << endl;
	cout << "Intelligence: " << intelligence << endl;
	cout << "Time: " << time << endl;
	cout << "Money: $" << money << endl;
	cout << "Your location is: " << getLocation() << endl;
}

bool Character::checkAttributes()
	{ 

	score = intelligence*time*money;
		if (getMoney() <= 0)
		{
			cout<<"\nYou ran out of money and cannot afford to eat so you died. GAME OVER."<<endl;
			system("PAUSE");
		return true;
		}
	 if (getIntelligence() <= 0)
	 {
			cout<<"\nYou lost all intelligence and are now in a vegetative state and unable to continue. GAME OVER."<<endl;
			system("PAUSE");
			return true;
	 }
		if (getTime() <= 0)
		{
			cout<<"\nYou ran out of sick days at work and cannot continue your dungeon adventure. GAME OVER."<<endl;
			system("PAUSE");
			return true;
		}
		if (getLocation() <= 0)
		{			
			cout<<"\nYOU WON THE GAME!"<<endl;
			system("PAUSE");
			return true;
		}
			
			
	}

Encounter::Encounter(Character* charac)
{
character = charac;
}

void Encounter::nothingHappens()
{
	
}

void Encounter::puzzles()
{
	
	int puzzSelect = (rand()%5)+1;
	cout << "Puzzle Time! ... Please read the question and enter your answer (Please provide all text answers in lowercase)." << endl;

 if(puzzSelect == 1)
 {
	 string userAnswer1;
	 string answer1 = "21"; 
	 cout << "What is 7 X 3?: ";
		cin >> userAnswer1;

		if(userAnswer1 == answer1)
		{
			character->setPlusMoney();
			cout<< "Congradulations you recieved +$10.00 money" << endl;
		}
		else
		{
			character->setMinusMoney();
			cout << "That is a completly preposterous answer.....its WRONG....you lose $20.00 money" << endl;
		}
}

 else if(puzzSelect == 2)
{
	 string userAnswer2;
	 string answer2 = "washington"; 
	 cout << "What is the last username of the first president of the United States?: ";
		cin >> userAnswer2;

		if(userAnswer2 == answer2)
		{
			character->setPlusMoney();
			cout<< "Congradulations you recieved +$10.00 money" << endl;
		}
		else
		{
			character->setMinusMoney();
			cout << "That is a completly preposterous answer.....its WRONG....you lose $20.00 money" << endl;
		}
}

 else if(puzzSelect == 3)
{
	 string userAnswer3;
	 string answer3 = "fruit"; 
	 cout << "Is a tomato a fruit or a vegetable?: ";
		cin >> userAnswer3;

		if(userAnswer3 == answer3)
		{
			character->setPlusMoney();
			cout<< "Congradulations you recieved +$10.00 money" << endl;
		}
		else
		{
			character->setMinusMoney();
			cout << "That is a completly preposterous answer.....its WRONG....you lose $20.00 money" << endl;
		}
}

 else if(puzzSelect == 4)
{
	 string userAnswer4;
	 string answer4 = "tiger"; 
	 cout << "What type of animal is Auburn's mascot Aubie?: ";
		cin >> userAnswer4;

		if(userAnswer4 == answer4)
		{
			character->setPlusMoney();
			cout<< "Congradulations you recieved +$10.00 money" << endl;
		}
		else
		{
			character->setMinusMoney();
			cout << "That is a completly preposterous answer.....its WRONG....you lose $20.00 money" << endl;
		}
}

 else if(puzzSelect == 5)
{
	 string userAnswer5;
	 string answer5 = "36"; 
	 cout << "What is the number 6 squared(6^2)?: ";
		cin >> userAnswer5;

		if(userAnswer5 == answer5)
		{
			character->setPlusMoney();
			cout<< "Congradulations you recieved +$10.00 money" << endl;
		}
		else
		{
			character->setMinusMoney();
			cout << "That is a completly preposterous answer.....its WRONG....you lose $20.00 money" << endl;
		}
}


}

void Encounter::encounterProfessor()
{
	cout << "You lose a random amount of time but gain 2 units of intelligence" << endl; 
	
	character->setGainIntelligence();
	character->setRandomTime();
	
}

void Encounter::encounterStudent()
{
	cout << "Because you stayed and talked you lose time." << endl; 
	
	character->setRandomTime();
}

void Encounter::attacked()
{
	cout << "OH NO! The crazed drug addict who attacked you made you dumber and wasted your time. You lose time and intelligence." << endl;
	character->setRandomTime();
	character->setLoseIntelligence();
}

void Encounter::gradePapers()
{
	cout << "But, on the bright side, you get +$10.00." << endl;
	
	character->setPlusMoney();
	character->setRandomTime();
}

void HighScores::readScores()
{
	ifstream file("HighScores.txt");
	int score = 0;
	v.clear();
	string nameString, scoreString;

	if ( file.is_open() )
	{
		while (getline( file, nameString) && getline( file, scoreString))
		{
			stringstream sStream;
			sStream << scoreString;
			sStream >> score;
			inputScore( nameString, score);
		}
	}
	file.close();

    return;
}

void HighScores::writeScores()
{
	ofstream file("HighScores.txt");

	for ( int i=0; i<v.size(); i++)
	{
		file << v[i].first << endl;
		file << v[i].second << endl;
	}

	file.close();
}

void HighScores::scoresOut()
{
	readScores();

	for( int i = 0; i < v.size(); i++ )
	{
		cout << v.at(i).first << " " << v.at(i).second << endl;
	}
}



int HighScores::addScore( string username, int highScore )
{
	readScores();
	
	inputScore(username, highScore);

	writeScores();
	return 0;
}

void HighScores::inputScore(string username, int highScore)
{
	bool insertScore = false;

	// Insert score into list
	for (int i=0; i<v.size(); i++)
	{
		if ( highScore > v.at(i).second )
		{
			insertScore = true;
			v.insert( v.begin() + i, make_pair(username, highScore) );
			break;
		}
	}

	if (v.size() > 0 && insertScore == false)
	{
		v.push_back( make_pair(username, highScore));
	}

	if (v.size() > 10)
	{
		v.erase( v.end()-1 );
	}

	if (v.size() == 0)
	{
		v.push_back( make_pair( username, highScore ) );
	}
}
Ah, the joys of porting from MSC++...

You need to #include <cstdlib>

Also, you should be getting some warnings about comparing signed and unsigned values. (For example, line 293 of your last post.)
Fix it portably with something like:
for ( unsigned i=0; i<(unsigned)v.size(); i++)

Hope this helps.
Topic archived. No new replies allowed.