Working with random like dice

This is a discussion on Working with random like dice within the C++ Programming forums, part of the General Programming Boards category; How do I make their str, def, sstr and so forth random as if they were rolling dice and the ...

1. Working with random like dice

How do I make their str, def, sstr and so forth random as if they were rolling dice and the set numbers are the max they can roll and 0 is the lleast?

Code:
```#include <iostream>
#include <cstdlib>
#include <string>
#include <time.h>

using namespace std;

class Character
{
public:
Character();
~Character();
int VIT;
int max_VIT;
int SPI;
int max_SPI;
int STR;
int max_STR;
int DEF;
int max_DEF;
int SSTR;
int max_SSTR;
int SDEF;
int max_SDEF;
int ACC;
int max_ACC;
int EVA;
int max_EVA;
int AGI;
int max_AGI;
int TURN;

int POT;
int max_POT;
int HPOT;
int max_HPOT;
int FPOT;
int max_FPOT;
int ETH;
int max_ETH;
int HETH;
int max_HETH;
int FETH;
int max_FETH;
int ELI;
int max_ELI;
int HELI;
int max_HELI;
int FELI;
int max_FELI;

void Command();
void Attack();
void Skill();
void Magic();
void Summon();
void Item();

char command[15];
char skill[15];
char magic[15];
char summon[15];
char item[15];
};

Character::Character()
{}
Character::~Character()
{}

class Swordsman
{
public:
Swordsman();
~Swordsman();
int VIT;
int max_VIT;
int SPI;
int max_SPI;
int STR;
int max_STR;
int DEF;
int max_DEF;
int SSTR;
int max_SSTR;
int SDEF;
int max_SDEF;
int ACC;
int max_ACC;
int EVA;
int max_EVA;
int AGI;
int max_AGI;
int TURN;

void Attack();
};

Swordsman::Swordsman()
{}
Swordsman::~Swordsman()
{}

Character Player;
Swordsman Enemy;
int X;
int Y;

void Character::Command()
{
string command;
cout<<"\n";
cin>>command;
cin.ignore();
if(command=="Attack"||command=="attack"){Character::Attack();}
else if(command=="Skill"||command=="skill"){Character::Skill();}
else if(command=="Magic"||command=="magic"){Character::Magic();}
else if(command=="Summon"||command=="summon"){Character::Summon();}
else if(command=="Item"||command=="item"){Character::Item();}
else{cout<<"(I don't think I should do that.)\n";Character::Command();}
}

void Character::Attack()
{
if(Player.ACC>=Enemy.EVA)
{X=Player.STR-Enemy.DEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}
}

void Character::Skill()
{
string skill;
cout<<"...";
cin>>skill;
cin.ignore();
if(skill=="Break-Weapon"||skill=="Break-weapon"||skill=="break-weapon")
{Player.SPI-5;
if(Player.ACC>=Enemy.EVA)
{Enemy.STR=Enemy.STR/2;cout<<"Enemy Strength Halved\n";}
else{cout<<"Miss\n";}}
else if(skill=="Break-Armor"||skill=="Break-armor"||skill=="break-armor")
{Player.SPI-5;
if(Player.ACC>=Enemy.EVA)
{Enemy.DEF=Enemy.DEF/2;cout<<"Enemy Defence Halved\n";}
else{cout<<"Miss\n";}}
else{cout<<"(I don't think I should do that.)\n";Character::Command();}
}

void Character::Magic()
{
string magic;
cout<<"...";
cin>>magic;
cin.ignore();
if(magic=="Fire"||magic=="fire")
{Player.SPI-5;
if(Player.ACC>=Enemy.EVA){X=Player.SSTR-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else{cout<<"(I don't think I should do that.)\n";Character::Command();}
}

void Character::Summon()
{
string summon;
cout<<"...";
cin>>summon;
cin.ignore();
if(summon=="Ifrit"||summon=="ifrit")
{Player.SPI-20;
if(Player.ACC*2>=Enemy.EVA){X=Player.SSTR*4-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else{cout<<"(I don't think I should do that.)\n";Character::Command();}
}

void Character::Item()
{
string item;
cout<<"...";
cin>>item;
cin.ignore();
if(item=="Potion"||item=="potion")
{Player.POT-1;X=Player.VIT/3;Player.VIT=Player.VIT+X;
if(Player.VIT>Player.max_VIT)
{Player.VIT=Player.max_VIT;cout<<X<<" Vitality Restored\n";}
else{cout<<X<<" Vitality Restored\n";}}
else{cout<<"(I don't think I should do that.)\n";Character::Command();}
}

void Swordsman::Attack()
{
cout<<"\n";
cout<<"Enemy's Turn\n";
if(Enemy.ACC>=Player.EVA)
{X=Enemy.STR-Player.DEF;
if(X>0){Player.VIT=Player.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}
}

int main()
{
Player.VIT=100;
Player.max_VIT=100;
Player.SPI=50;
Player.max_SPI=50;
Player.STR=rand()%20;
Player.max_STR=20;
Player.DEF=rand()%15;
Player.max_DEF=15;
Player.SSTR=rand()%15;
Player.max_SSTR=15;
Player.SDEF=rand()%15;
Player.max_SDEF=15;
Player.ACC=rand()%10;
Player.max_ACC=10;
Player.EVA=rand()%10;
Player.max_EVA=10;
Player.AGI=rand()%5;
Player.max_AGI=5;
Player.TURN=0;

Player.POT=5;
Player.max_POT=100;
Player.HPOT=5;
Player.max_HPOT=100;
Player.FPOT=5;
Player.max_FPOT=100;
Player.ETH=5;
Player.max_ETH=100;
Player.HETH=5;
Player.max_HETH=100;
Player.FETH=5;
Player.max_FETH=100;
Player.ELI=5;
Player.max_ELI=100;
Player.HELI=5;
Player.max_HELI=100;
Player.FELI=5;
Player.max_FELI=100;

Enemy.VIT=100;
Enemy.max_VIT=100;
Enemy.SPI=50;
Enemy.max_SPI=50;
Enemy.STR=rand()%15;
Enemy.max_STR=15;
Enemy.DEF=rand()%15;
Enemy.max_DEF=15;
Enemy.SSTR=rand()%15;
Enemy.max_SSTR=15;
Enemy.SDEF=rand()%15;
Enemy.max_SDEF=15;
Enemy.ACC=rand()%10;
Enemy.max_ACC=10;
Enemy.EVA=rand()%10;
Enemy.max_EVA=10;
Enemy.AGI=rand()%5;
Enemy.max_AGI=5;
Enemy.TURN=0;

cout<<"He challenges you to a fight and you accept.\n";

if(Player.AGI>=Enemy.AGI){Player.TURN=Player.TURN+1;}
else{Enemy.TURN=Enemy.TURN+1;}

do
{
if(Player.TURN>Enemy.TURN){Player.Command();Enemy.TURN=Enemy.TURN+2;}
else if(Player.TURN<Enemy.TURN){Enemy.Attack();Player.TURN=Player.TURN+2;}
else{
if(Player.AGI>=Enemy.AGI){Player.TURN=Player.TURN+1;}
else{Enemy.TURN=Enemy.TURN+1;}}
}
while(Player.VIT>0||Enemy.VIT>0);
if(Player.VIT<=0){cout<<"You Died\n";cout<<"Game Over\n";}
else{cout<<"Victory\n";}
cin.get();
}```

2. You should put all the code to set the stats for those two objects in their respective constructors and set them using calls to the rand function.

3. haha i have no idea what you just said

4. Allow me to demonstrate my tutorial technique.
C++ Random Numbers
After you learn random numbers, build a constructor for your class, and set the numbers with rand().

5. Code:
```      public:
Character();
~Character();
int VIT;
int max_VIT;
int SPI;
int max_SPI;
int STR;
int max_STR;
.
.
.
int FELI;
int max_FELI;```
A class that requires that many member variables is probably not
designed correctly. Its poorly designed as well - generally
member variables should be private - you shouldn't have lines
of code like the following in main: Player.VIT=100; You should
only be able to access your data through member functions.

Here's an example of a simple class that implements a contructor
to set all the variables to default values and also an overloaded
constructor where you can specify the values of the members
explicitly:

Code:
```#include <iostream>

using namespace std;

class Thing
{
private:
int x;
char y;
float z;

public:
Thing (); //Default Constructor
Thing (int X, char Y, float Z); //Overloaded Constructor

void Setx (int X);
int Getx ();

void Sety (char Y);
char Gety ();

void Setz (float Z);
float Getz ();
};

/////////////////////////////////////////////////////////////////

Thing::Thing()
{
x = 0;
y = '0';
z = 0.0;
}

Thing::Thing(int X, char Y, float Z)
{
x = X;
y = Y;
z = Z;
}

void Thing::Setx(int X)
{
x = X;
}

int Thing::Getx()
{
return x;
}

void Thing::Sety(char Y)
{
y = Y;
}

char Thing::Gety()
{
return y;
}

void Thing::Setz(float Z)
{
z = Z;
}

float Thing::Getz()
{
return z;
}
/////////////////////////////////////////////////////////////////

int main (void)
{
Thing A;
Thing B (10, 'R', 3.2);

cout << "x: " << A.Getx () << endl;
cout << "y: " << A.Gety () << endl;
cout << "z: " << A.Getz () << endl << endl;

cout << "x: " << B.Getx () << endl;
cout << "y: " << B.Gety () << endl;
cout << "z: " << B.Getz () << endl << endl;

return 0;
}

/////////////////////////////////////////////////////////////////```

6. ok i did the little random system thing but now everything always equals 0

Code:
```#include <iostream>
#include <cstdlib>
#include <string>
#include <time.h>

using namespace std;

class Character
{
public:
Character();
~Character();
int VIT;
int max_VIT;
int SPI;
int max_SPI;
int rang_STR;
int min_STR;
int STR;
int max_STR;
int rang_DEF;
int min_DEF;
int DEF;
int max_DEF;
int rang_SSTR;
int min_SSTR;
int SSTR;
int max_SSTR;
int rang_SDEF;
int min_SDEF;
int SDEF;
int max_SDEF;
int rang_ACC;
int min_ACC;
int ACC;
int max_ACC;
int rang_EVA;
int min_EVA;
int EVA;
int max_EVA;
int rang_AGI;
int min_AGI;
int AGI;
int max_AGI;
int TURN;

int POT;
int max_POT;
int HPOT;
int max_HPOT;
int FPOT;
int max_FPOT;
int ETH;
int max_ETH;
int HETH;
int max_HETH;
int FETH;
int max_FETH;
int ELI;
int max_ELI;
int HELI;
int max_HELI;
int FELI;
int max_FELI;

void Command();
void Attack();
void Skill();
void Magic();
void Summon();
void Item();

};

Character::Character()
{}
Character::~Character()
{}

class Swordsman
{
public:
Swordsman();
~Swordsman();
int VIT;
int max_VIT;
int SPI;
int max_SPI;
int rang_STR;
int min_STR;
int STR;
int max_STR;
int rang_DEF;
int min_DEF;
int DEF;
int max_DEF;
int rang_SSTR;
int min_SSTR;
int SSTR;
int max_SSTR;
int rang_SDEF;
int min_SDEF;
int SDEF;
int max_SDEF;
int rang_ACC;
int min_ACC;
int ACC;
int max_ACC;
int rang_EVA;
int min_EVA;
int EVA;
int max_EVA;
int rang_AGI;
int min_AGI;
int AGI;
int max_AGI;
int TURN;

void Attack();
};

Swordsman::Swordsman()
{}
Swordsman::~Swordsman()
{}

Character Player;
Swordsman Enemy;
int X;
int Y;

void Character::Command()
{
string command;
cout<<"\n";
cin>>command;
cin.ignore();
if(command=="Attack"||command=="attack"){Character::Attack();}
else if(command=="Skill"||command=="skill"){Character::Skill();}
else if(command=="Magic"||command=="magic"){Character::Magic();}
else if(command=="Summon"||command=="summon"){Character::Summon();}
else if(command=="Item"||command=="item"){Character::Item();}
else{cout<<"(I don't think I should do that.)\n";Character::Command();}
}

void Character::Attack()
{
if(Player.ACC>=Enemy.EVA)
{X=Player.STR-Enemy.DEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}
}

void Character::Skill()
{
string skill;
cout<<"...";
cin>>skill;
cin.ignore();
if(skill=="Break-Weapon"||skill=="Break-weapon"||skill=="break-weapon")
{Player.SPI=Player.SPI-5;
if(Player.ACC>=Enemy.EVA)
{Enemy.STR=Enemy.STR/2;cout<<"Enemy Strength Halved\n";}
else{cout<<"Miss\n";}}
else if(skill=="Break-Armor"||skill=="Break-armor"||skill=="break-armor")
{Player.SPI=Player.SPI-5;
if(Player.ACC>=Enemy.EVA)
{Enemy.DEF=Enemy.DEF/2;cout<<"Enemy Defence Halved\n";}
else{cout<<"Miss\n";}}
else if(skill=="Escape"||skill=="escape")
{Player.SPI=Player.SPI-5;
if(Player.AGI>=Enemy.AGI){cout<<"Escape Successful\n";abort();}
else{cout<<"Escape Failed\n";}}
else{cout<<"(I don't think I should do that.)\n";Character::Command();}
}

void Character::Magic()
{
string magic;
cout<<"...";
cin>>magic;
cin.ignore();
if(magic=="Fire"||magic=="fire")
{Player.SPI=Player.SPI-5;
if(Player.ACC>=Enemy.EVA){X=Player.SSTR-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Fira"||magic=="fira")
{Player.SPI=Player.SPI-10;
if(Player.ACC>=Enemy.EVA){X=(Player.SSTR*2)-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Firaga"||magic=="firaga")
{Player.SPI=Player.SPI-15;
if(Player.ACC>=Enemy.EVA){X=(Player.SSTR*3)-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Flare"||magic=="flare")
{Player.SPI=Player.SPI-20;
if(Player.ACC>=Enemy.EVA){X=(Player.SSTR*4)-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Blizzard"||magic=="blizzard")
{Player.SPI=Player.SPI-5;
if(Player.ACC>=Enemy.EVA){X=Player.SSTR-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Blizzara"||magic=="blizzara")
{Player.SPI=Player.SPI-10;
if(Player.ACC>=Enemy.EVA){X=(Player.SSTR*2)-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Blizzaga"||magic=="blizzaga")
{Player.SPI=Player.SPI-15;
if(Player.ACC>=Enemy.EVA){X=(Player.SSTR*3)-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Ultima"||magic=="ultima")
{Player.SPI=Player.SPI-20;
if(Player.ACC>=Enemy.EVA){X=(Player.SSTR*4)-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Thunder"||magic=="Thunder")
{Player.SPI=Player.SPI-5;
if(Player.ACC>=Enemy.EVA){X=Player.SSTR-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Thundara"||magic=="thundara")
{Player.SPI=Player.SPI-10;
if(Player.ACC>=Enemy.EVA){X=Player.SSTR-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Thundaga"||magic=="thundaga")
{Player.SPI=Player.SPI-15;
if(Player.ACC>=Enemy.EVA){X=(Player.SSTR*3)-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Meteor"||magic=="meteor")
{Player.SPI=Player.SPI-20;
if(Player.ACC>=Enemy.EVA){X=(Player.SSTR*4)-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else if(magic=="Cure"||magic=="cure")
{Player.SPI=Player.SPI-5;Player.VIT=Player.VIT+Player.SSTR;
cout<<Player.SSTR<<" Vitality Restored\n";}
else if(magic=="Cura"||magic=="cura")
{Player.SPI=Player.SPI-10;Player.VIT=Player.VIT+(Player.SSTR*2);
cout<<Player.SSTR*2<<" Vitality Restored\n";}
else if(magic=="Curaga"||magic=="curaga")
{Player.SPI=Player.SPI-15;Player.VIT=Player.VIT+(Player.SSTR*3);
cout<<Player.SSTR*3<<" Vitality Restored\n";}
else if(magic=="Scan"||magic=="scan")
{Player.SPI=Player.SPI-5;
cout<<Player.VIT<<"/"<<Player.max_VIT<<" Vitality\n";
cout<<Player.SPI<<"/"<<Player.max_SPI<<" Spirit\n";
cout<<"Enemy's Stats\n";
cout<<Enemy.VIT<<"/"<<Enemy.max_VIT<<" Vitality\n";
cout<<Enemy.SPI<<"/"<<Enemy.max_SPI<<" Spirit\n";}

else{cout<<"(I don't think I should do that.)\n";Character::Command();}
}

void Character::Summon()
{
string summon;
cout<<"...";
cin>>summon;
cin.ignore();
if(summon=="Ifrit"||summon=="ifrit")
{Player.SPI-20;
if(Player.ACC*2>=Enemy.EVA){X=Player.SSTR*4-Enemy.SDEF;
if(X>0){Enemy.VIT=Enemy.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}}
else{cout<<"(I don't think I should do that.)\n";Character::Command();}
}

void Character::Item()
{
string item;
cout<<"...";
cin>>item;
cin.ignore();
if(item=="Potion"||item=="potion")
{Player.POT-1;X=Player.VIT/3;Player.VIT=Player.VIT+X;
if(Player.VIT>Player.max_VIT)
{Player.VIT=Player.max_VIT;cout<<X<<" Vitality Restored\n";}
else{cout<<X<<" Vitality Restored\n";}}
else{cout<<"(I don't think I should do that.)\n";Character::Command();}
}

void Swordsman::Attack()
{
cout<<"\n";
cout<<"Enemy's Turn\n";
if(Enemy.ACC>=Player.EVA)
{X=Enemy.STR-Player.DEF;
if(X>0){Player.VIT=Player.VIT-X;cout<<X<<" Damage\n";}
else{cout<<"0 Damage\n";}}
else{cout<<"Miss\n";}
}

int main()
{
srand((unsigned)time(0));

Player.VIT=100;
Player.max_VIT=100;
Player.SPI=50;
Player.max_SPI=50;

Player.rang_STR=(Player.max_STR-Player.min_STR)+1;
Player.min_STR=1;
Player.STR=Player.min_STR+int(Player.rang_STR*rand()/(RAND_MAX + 1.0));
Player.max_STR=20;

Player.rang_DEF=(Player.max_DEF-Player.min_DEF)+1;
Player.min_DEF=1;
Player.DEF=Player.min_DEF+int(Player.rang_DEF*rand()/(RAND_MAX + 1.0));
Player.max_DEF=15;

Player.rang_SSTR=(Player.max_SSTR-Player.min_SSTR)+1;
Player.min_SSTR=1;
Player.SSTR=Player.min_SSTR+int(Player.rang_SSTR*rand()/(RAND_MAX + 1.0));
Player.max_SSTR=15;

Player.rang_SDEF=(Player.max_SDEF-Player.min_SDEF)+1;
Player.min_SDEF=1;
Player.SDEF=Player.min_SDEF+int(Player.rang_SDEF*rand()/(RAND_MAX + 1.0));
Player.max_SDEF=15;

Player.rang_ACC=(Player.max_ACC-Player.min_ACC)+1;
Player.min_ACC=1;
Player.ACC=Player.min_ACC+int(Player.rang_ACC*rand()/(RAND_MAX + 1.0));
Player.max_ACC=10;

Player.rang_EVA=(Player.max_EVA-Player.min_EVA)+1;
Player.min_EVA=1;
Player.EVA=Player.min_EVA+int(Player.rang_EVA*rand()/(RAND_MAX + 1.0));
Player.max_EVA=10;

Player.rang_AGI=(Player.max_AGI-Player.min_AGI)+1;
Player.min_AGI=1;
Player.AGI=Player.min_AGI+int(Player.rang_AGI*rand()/(RAND_MAX + 1.0));
Player.max_AGI=5;

Player.TURN=0;

Player.POT=5;
Player.max_POT=100;
Player.HPOT=5;
Player.max_HPOT=100;
Player.FPOT=5;
Player.max_FPOT=100;
Player.ETH=5;
Player.max_ETH=100;
Player.HETH=5;
Player.max_HETH=100;
Player.FETH=5;
Player.max_FETH=100;
Player.ELI=5;
Player.max_ELI=100;
Player.HELI=5;
Player.max_HELI=100;
Player.FELI=5;
Player.max_FELI=100;

Enemy.VIT=100;
Enemy.max_VIT=100;
Enemy.SPI=50;
Enemy.max_SPI=50;

Enemy.rang_STR=(Enemy.max_STR-Enemy.min_STR)+1;
Enemy.min_STR=1;
Enemy.STR=Enemy.min_STR+int(Enemy.rang_STR*rand()/(RAND_MAX + 1.0));
Enemy.max_STR=15;

Enemy.rang_DEF=(Enemy.max_DEF-Enemy.min_DEF)+1;
Enemy.min_DEF=1;
Enemy.DEF=Enemy.min_DEF+int(Enemy.rang_DEF*rand()/(RAND_MAX + 1.0));
Enemy.max_DEF=15;

Enemy.rang_SSTR=(Enemy.max_SSTR-Enemy.min_SSTR)+1;
Enemy.min_SSTR=1;
Enemy.SSTR=Enemy.min_SSTR+int(Enemy.rang_SSTR*rand()/(RAND_MAX + 1.0));
Enemy.max_SSTR=15;

Enemy.rang_SDEF=(Enemy.max_SDEF-Enemy.min_SDEF)+1;
Enemy.min_SDEF=1;
Enemy.SDEF=Enemy.min_SDEF+int(Enemy.rang_SDEF*rand()/(RAND_MAX + 1.0));
Enemy.max_SDEF=15;

Enemy.rang_ACC=(Enemy.max_ACC-Enemy.min_ACC)+1;
Enemy.min_ACC=1;
Enemy.ACC=Enemy.min_ACC+int(Enemy.rang_ACC*rand()/(RAND_MAX + 1.0));
Enemy.max_ACC=10;

Enemy.rang_EVA=(Enemy.max_EVA-Enemy.min_EVA)+1;
Enemy.min_EVA=1;
Enemy.EVA=Enemy.min_EVA+int(Enemy.rang_EVA*rand()/(RAND_MAX + 1.0));
Enemy.max_EVA=10;

Enemy.rang_AGI=(Enemy.max_AGI-Enemy.min_AGI)+1;
Enemy.min_AGI=1;
Enemy.AGI=Enemy.min_AGI+int(Enemy.rang_AGI*rand()/(RAND_MAX + 1.0));
Enemy.max_AGI=5;

Enemy.TURN=0;

cout<<"He challenges you to a fight and you accept.\n";

if(Player.AGI>=Enemy.AGI){Player.TURN=Player.TURN+1;}
else{Enemy.TURN=Enemy.TURN+1;}

do
{
if(Player.TURN>Enemy.TURN){Player.Command();Enemy.TURN=Enemy.TURN+2;}
else if(Player.TURN<Enemy.TURN){Enemy.Attack();Player.TURN=Player.TURN+2;}
else{
if(Player.AGI>=Enemy.AGI){Player.TURN=Player.TURN+1;}
else{Enemy.TURN=Enemy.TURN+1;}}
}
while(Player.VIT>=1&&Enemy.VIT>=1);
if(Player.VIT<1){cout<<"You Died\n";cout<<"Game Over\n";}
else{cout<<"Victory\n";}
cin.get();
}```

7. was there any reason to post 435 lines of code to diagnose your
problem? You didn't listen to what I said about class design and
the amount of variables it uses - your code is poorly written and
overly complex - your character and swordsman classes are very
similar - why not make character a base class and allow
swordsman to inherit from it - there's just way too much code
to wade through - just redesign your program - AND USE CONSTRUCTORS TO INITIALISE DATA MEMBERS!!!

8. And I don't think he used rand() anywhere either.

9. In the main():

Code:
```Player.rang_STR=(Player.max_STR-Player.min_STR)+1;
Player.min_STR=1;
Player.STR=Player.min_STR+int(Player.rang_STR*rand  ()/(RAND_MAX + 1.0));
Player.max_STR=20;```
and many similar.

Where does Player.max_STR and Player.min_str get their initial values in the first line? (Both are assigned later.)

The use of rand() seems also faulty. You'll probably need something like:
Code:
`Player.STR = Player.min_str + rand() % Player.rand_STR`