• Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!

    You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!

Hmmm...help(C++ begginner)

Gnes

Smash Master
Joined
Aug 8, 2007
Messages
3,666
Location
In Another Dimension...
#include<iostream>

using namespace std;
const int SIZE=10;

struct Coordinate
{
int X;
int Y;
};

struct Player
{
char name[50];
int steps;
Coordinate location;
};


void GameSetup(Player& player, Coordinate& winPosition, bool tiles[SIZE][SIZE]);
void PrintTiles();

int main()
{
bool tiles[SIZE][SIZE];
GameSetup(); <--------------------------------------------Problem Here
PrintTiles();


system("PAUSE");
return 0;
}

Basically i dont know what to put there. Im trying to create a maze. The function definition which has the maze is given to us so basically i just dont know what to put there. Help.
 

Dastrn

BRoomer
BRoomer
Joined
Jul 16, 2005
Messages
9,472
Location
Indiana
For starters, I'm curious why you're using struct in c++. It's kind of old school C style stuff. C++ gives you actual Object Oriented Programming. You should take advantage of that with "class" instead of "struct". It will keep things cleaner.
You'll have to describe in a lot more detail what you want your program to do before we can be much help.
 

Kirby King

Master Lameoid
Premium
BRoomer
Joined
Feb 8, 2002
Messages
7,577
Location
Being a good little conformist
void GameSetup(Player& player, Coordinate& winPosition, bool tiles[SIZE][SIZE]);

So this line looks important. That's the function prototype for GameSetup(), which apparently takes three arguments: a Player, a Coordinate, and a 2D array of tiles.

Also, to sort of reiterate what Dastrn said, it looks like you're expected to use classes instead of structs.
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
A struct is a class, except the default access level is public. Better classes though because its standard.

And you're going to need a loop somewhere. Rather than using system("PAUSE") to just pause it, you're better off breaking out some either way.

Are you just starting the language?
 

Dastrn

BRoomer
BRoomer
Joined
Jul 16, 2005
Messages
9,472
Location
Indiana
A struct is a class, except the default access level is public. Better classes though because its standard.

And you're going to need a loop somewhere. Rather than using system("PAUSE") to just pause it, you're better off breaking out some either way.

Are you just starting the language?
System pause isn't horrible. If he's stuck using windows, and it's a simple enough program, then it's not hurting anything at all.

Struct technically isn't a good idea. It's C, not C++, and it won't take him very far if he keeps using it.

He said in the title of the thread that he's a beginner.
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
Forgot to mention that's what allegedly other people say. Screw me not rereading. cin.get() works the same and is what people recommend, but system("PAUSE") is fine for simple stuff. But in nearly every help thread ever, for some reason people say "don't use pause", so I don't know what to think.

On struct vs classes it really makes no difference. A struct has the exact same features as a class and works exactly the same way in C++. The only difference is that in a struct, the default access is public, and its private in classes, as I mentioned. However, it usually isn't a good idea for complex stuff because class is the defacto keyword. However, he's using a struct for a coordinate. Looking at how he wants to use it, he'd have to do
class Coordinate
{
public:
int X;
int Y;
};

to get the same effect using classes. This seems like the textbook example of when you should use a struct.

And I failed in reading the thread title yet again, but if you're trying to make a game in C++ just starting out, did you at least try other languages, or is this an assignment?
 

TheBuzzSaw

Young Link Extraordinaire
Moderator
BRoomer
Joined
Jul 21, 2005
Messages
10,479
lolwut??

Structs are still very common and useful in C++. Classes are not "bigger, badder structs". Classes do not suddenly render structs obsolete. As was mentioned, in terms of syntax, classes and structs are technically identical (aside from the public/private default). However, semantically, classes form objects with defined behavior, while structs form simple data clusters (that lack any real behavior).

For instance, I think the Coordinate struct is completely valid. It has an x and a y. It doesn't need any advanced behavior. Changing to a class (and slapping "public" in there) is a bad idea in terms of readability.
 

the_dannobot

Smash Rookie
Joined
May 11, 2006
Messages
18
Location
Austin
The parameters for the call to GameSetup() have to match the function footprint. So you'll need to pass in a reference to a Player object, a reference to a Coordinate object, and a 2d array of bools of size SIZExSIZE.

int main()
{
bool tiles[SIZE][SIZE];
Player myPlayer;
Coordinate myWinCoordinate;
GameSetup(myPlayer, myWinCoordinate, tiles);
PrintTiles();

system("PAUSE");
return 0;
}

This still won't work until you provide a definition for teh GameSetup function though.
Also in this example I would use classes over structs because the member variables can be initialized in a constructor.
 
Top Bottom