no matter what i do i cant seem to get rid of this thing where no matter where i place my void namephase() it always has an error saying it expected a ';' please help!
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
usingnamespace std;
void battlephase;
void namephase;
class Player;
class Player
{
public:
int health;
int exp;
int level;
int atk;
Player (bool Player)
{
health = 10;
level = 1;
exp = 0;
atk = 10;
}
};
int main()
{
Player P(true);
int damageDealt;
char name[10];
char Action;
int money;
money=1000;
cout<<"\tWelcome to A Warrior Game!\n\tHere is where your adventure will begin.\n\tEnjoy!"<<endl;
void namephase()
{
cout<<"\n\nEnter Your name."<<endl;
cin>>name;
cout<<"Your name is "<<name<<"?\n 1=Yes 2=No"<<endl;
cin>>Action;
if(Action=='1')
{
cout<<"Very well\n"<<endl;
}
if(Action=='2')
{
cout<<"What is your name?"<<endl;
cin>>name;
cout<<"Your name is now "<<name<<"!\n"<<endl;
}
}
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
usingnamespace std;
void battlephase;
void namephase;
class Player;
class Player
{
public:
int health;
int exp;
int level;
int atk;
Player (bool Player)
{
health = 10;
level = 1;
exp = 0;
atk = 10;
}
};
void namephase()
{
cout<<"\n\nEnter Your name."<<endl;
cin>>name;
cout<<"Your name is "<<name<<"?\n 1=Yes 2=No"<<endl;
cin>>Action;
if(Action=='1')
{
cout<<"Very well\n"<<endl;
}
if(Action=='2')
{
cout<<"What is your name?"<<endl;
cin>>name;
cout<<"Your name is now "<<name<<"!\n"<<endl;
}
}
int main()
{
Player P(true);
int damageDealt;
char name[10];
char Action;
int money;
money=1000;
cout<<"\tWelcome to A Warrior Game!\n\tHere is where your adventure will begin.\n\tEnjoy!"<<endl;
void namephase(); //here you call that function
}
Something else I'd like to note is that you cannot define your functions* in main. You need to do that outside, which would mean adding a few arguments to your function and moving it outside of main. :)
EDIT: Ninjas.
*Lambda functions can and should be defined inside a function, but I don't see why you'd need a lambda function here.
You'll need to pass the objects you need to the function when you invoke (call) it. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void Function(int pValue);
int main(void)
{
int My_int(0);
// Call my function and give it 'My_int'
::Function(My_int);
// The '::' means the identifier following it resides within the
// global namespace.
return(0);
}
void Function(int pValue)
{
//...
}
When ::Function() is called, My_int is copied into pValue of ::Function(). This is called passing by value. Modifications made to pValue will not affect My_int because it's a copy. However, by looking at your code, you'll need the functionality of references[1], or you'll never get anything done.
However, by looking at your code, you'll need the functionality of references, or you'll never get anything done.
Well even with references he won't get anything done. He is declaring variables in main but using them in the functions at the top of the source so he will just keep getting errors. Tried writing up a 'fix' for the errors, but keep losing my place using his existing code.
BHXSpecter: That's the whole idea of prameters. What he/she needs to do is add the appropriate parameters, replace all references to the objects within main() with the corresponding parameters, then call the function(s). Global variables are not condoned by many.
@Framework:
Yes, I know, I understand references better than pointers to be honest. He may not know parameters (I never assume anyone knows even the basics of the language). References will fix it the functions, but still going to have errors after that.
1 2 3 4
Player P(true);
Boar E(true);
Gunthor G(true);
According to his code only the player class is defined so Boar and Gunthor will return errors (unless I missed that part of his code too). His code makes me feel he is trying too much at once and getting overwhelmed on it.
i probably am trying too much at once. but i dont know what i am supposed to do so i end up looking up a bunch of shit and i probably screwed myself on it.
Yeah, I figured that was the problem. I still am the same way with more advanced things like memory allocation and pointers still lose me. Not to mention linked lists, stacks, queue, heap, etc. If you haven't yet, just go through the lessons here on the site as they are good. Then maybe look into getting a book or two (I have The C++ Programming Language by Bjarne Stroustrup and C++ Primer). Don't give up on this, but it is better to start with tutorials and such to learn C++ basics, then if you want to make a game move onto Allegro (http://www.allegro.cc ), SDL(http://www.libsdl.org ), or SFML (http://www.sfml-dev.org ). Then you can move to XNA or OpenGL. If you just want to program then you could learn Qt and do GUI programming. Then of course you get into scripting languages like Python, Perl, Lua, Ruby, etc. C++ is a great starting point for programming, just have to find the right resources (this site and the tutorials being one such resource).