Skip to main content
removed disparaging meta-remark from answer
Source Link
Vogel612
  • 25.5k
  • 7
  • 59
  • 141

It's extremely unclear what you're asking (or whether your post might just be a troll post), so expect it to get closed shortly.


typedef struct weapons { int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2; } weapons; 

The typedef struct X { ... } X; pattern is a C-ism; in C++ you don't need the typedef and can just write struct X { ... };.

You're creating a struct type named weapons with a bunch of per-instance member variables. This is almost certainly not what you meant to do. Probably what you meant was

enum class Weapon { dagger = 2, sword = 3, axe = 4, mace = 5, }; 

so that you could later write

Weapon w = Weapon::sword; if (w == Weapon::axe) { ... } 

What you actually wrote, unfortunately, is simply nonsense.


character characterCreation(string name); 

Look up the C++ notion of "constructors" (and also destructors). What you have here would normally be spelled something like

Character::Character(const std::string& name) { this->name = name; this->strength = rand() % 5 + 5; } 

and so on.

Also consider writing yourself a helper function

int randint(int lo, int hi) { return rand() % (hi - lo) + lo; } 

so that you can write simply

 this->strength = randint(5, 10); 

Ninety percent of what we call "programming" is just finding sources of repetition and eliminating them.

It's extremely unclear what you're asking (or whether your post might just be a troll post), so expect it to get closed shortly.


typedef struct weapons { int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2; } weapons; 

The typedef struct X { ... } X; pattern is a C-ism; in C++ you don't need the typedef and can just write struct X { ... };.

You're creating a struct type named weapons with a bunch of per-instance member variables. This is almost certainly not what you meant to do. Probably what you meant was

enum class Weapon { dagger = 2, sword = 3, axe = 4, mace = 5, }; 

so that you could later write

Weapon w = Weapon::sword; if (w == Weapon::axe) { ... } 

What you actually wrote, unfortunately, is simply nonsense.


character characterCreation(string name); 

Look up the C++ notion of "constructors" (and also destructors). What you have here would normally be spelled something like

Character::Character(const std::string& name) { this->name = name; this->strength = rand() % 5 + 5; } 

and so on.

Also consider writing yourself a helper function

int randint(int lo, int hi) { return rand() % (hi - lo) + lo; } 

so that you can write simply

 this->strength = randint(5, 10); 

Ninety percent of what we call "programming" is just finding sources of repetition and eliminating them.

typedef struct weapons { int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2; } weapons; 

The typedef struct X { ... } X; pattern is a C-ism; in C++ you don't need the typedef and can just write struct X { ... };.

You're creating a struct type named weapons with a bunch of per-instance member variables. This is almost certainly not what you meant to do. Probably what you meant was

enum class Weapon { dagger = 2, sword = 3, axe = 4, mace = 5, }; 

so that you could later write

Weapon w = Weapon::sword; if (w == Weapon::axe) { ... } 

What you actually wrote, unfortunately, is simply nonsense.


character characterCreation(string name); 

Look up the C++ notion of "constructors" (and also destructors). What you have here would normally be spelled something like

Character::Character(const std::string& name) { this->name = name; this->strength = rand() % 5 + 5; } 

and so on.

Also consider writing yourself a helper function

int randint(int lo, int hi) { return rand() % (hi - lo) + lo; } 

so that you can write simply

 this->strength = randint(5, 10); 

Ninety percent of what we call "programming" is just finding sources of repetition and eliminating them.

Source Link
Quuxplusone
  • 19.7k
  • 2
  • 44
  • 91

It's extremely unclear what you're asking (or whether your post might just be a troll post), so expect it to get closed shortly.


typedef struct weapons { int dagger = 2, sword = 3, axe = 4, mace = 5, bow = 3, arrows = 2; } weapons; 

The typedef struct X { ... } X; pattern is a C-ism; in C++ you don't need the typedef and can just write struct X { ... };.

You're creating a struct type named weapons with a bunch of per-instance member variables. This is almost certainly not what you meant to do. Probably what you meant was

enum class Weapon { dagger = 2, sword = 3, axe = 4, mace = 5, }; 

so that you could later write

Weapon w = Weapon::sword; if (w == Weapon::axe) { ... } 

What you actually wrote, unfortunately, is simply nonsense.


character characterCreation(string name); 

Look up the C++ notion of "constructors" (and also destructors). What you have here would normally be spelled something like

Character::Character(const std::string& name) { this->name = name; this->strength = rand() % 5 + 5; } 

and so on.

Also consider writing yourself a helper function

int randint(int lo, int hi) { return rand() % (hi - lo) + lo; } 

so that you can write simply

 this->strength = randint(5, 10); 

Ninety percent of what we call "programming" is just finding sources of repetition and eliminating them.