Click to See Complete Forum and Search --> : problems coding game with classes


greenismn
March 12th, 2008, 05:01 PM
Hello, I am having trouble with this code for a game that must use classes. I am having trouble especially with the Character class. This class is used throughout the code to increase or decrease money, time and intellegence. Steps must also be increased or decreased. If anyone can tell me what I am doing wrong I would greatly appreciate it. I have not ironed out all the details of the game yet, like I need to add some more loops and things to control the menu's and tell the user if they have won the game, and I have not finished the part where I write the scores to an outside file but I will deal with this stuff when I figure out what it is I am doing with the variables. As is the compiler gives me the following errors.

Undefined symbol 'inital_time' in function Character::init_character()
Undefined symbol 'intial_intel' in function Character::init_character() 'initial_intel' is assigned a value that is never used in function Character::init_character()
'initial_money' is assigned a value that is never used in function Character::init_character()
'initial_time' is assigned a value that is never used in function Character::init_character()
Undefined symbol 'initial_time'
Qualifier 'Encounter' is not a class or namespace name
Declaration terminated incorrectly
Qualifier 'Menu' is not a class or namespace name
Declaration terminated incorrectly

Thanks so much for the help.

stephendoyle75
March 12th, 2008, 05:09 PM
int initial_time;
int initial_intel;
int initial_money;

These are defined as both class private members and also as local variables in Character::init_character(). This needs to be cleaned up - I'd suggest just using the ones that are class members.


int Character::init_character()
{
int initial_time=0;
int initial_money=0;
int initial_intel=0;
initial_time=rand.generate_random_number();
initial_money=rand.generate_random_number();
initial_intel=rand.generate_random_number();
return(inital_time, initial_money, intial_intel);
}

You can't return multiple values using the return statement.

Paul McKenzie
March 12th, 2008, 05:13 PM
Hello, I am having trouble with this code for a game that must use classes.So you wrote this whole thing without compiling it once?

#include <time>
#include <math>

1) There are no such headers in standard C++. The headers are <ctime> and <cmath>. This is why you always compile during development of code, so that simple things like this are found out immediately.

2) Remove the header <cstdlib>

3) This is illegal, as function definitions must define a return type:

class Randomization
{
public:
int generate_random_number();
private:
double random_number;
};

Regards,

Paul McKenzie

greenismn
March 12th, 2008, 05:35 PM
Thanks guys, those are good suggestions. I realize my code is a little sloppy, i usually do it quick and dirty first and then once it compiles I will clean it up and add details. Ive been looking at my code and I am a little confused on how to do the get and set functions in the Character class. I thought I was doing them right but my compiler tells me otherwise =). But once again thanks for all of the help.