Actually, delete("") worked perfectly. Now I have a new, unrelated bug, though... My monst() function (it randomly pulls up a monster and loads the opponent's struct with the enemy info) isn't reloading the enemy stats every time I start a "quick battle". Also, when I run away from a battle (this problem seems to be in battle() ), I still gain exp and money even though I don't want it to. Here are the two functions (and the function that calls them):
monst()
Code:
void monst() {
int rando = 1+rand()%500;
if (player.lev >= 1 && player.lev <= 3)
{
if (rando <= 50 && rando >= 0)
{
opponent.nam = "Bug";
opponent.lev = 1;
opponent.att = 3;
opponent.def = 2;
opponent.agi = 2;
opponent.mon = 10;
opponent.sta = 10;
opponent.exp = 5;
}
else if (rando > 50)
{
opponent.nam = "Rabbit";
opponent.lev = 1;
opponent.att = 3;
opponent.def = 3;
opponent.agi = 3;
opponent.mon = 5;
opponent.sta = 15;
opponent.exp = 10;
}
}
}
battle() -- which calls monst()
Code:
void battle() {
string sel;
monst();
while (player.tempsta > 0 || opponent.sta > 0)
{
cout << player.nam << ": Level " << player.lev << "; Stamina: " << player.tempsta << endl;
cout << opponent.nam << ": Level " << opponent.lev << "; Stamina: " << opponent.sta << endl << endl;
cout << "Attack (press a)\n";
cout << "Defend (press d)\n";
cout << "Run (press r)\n\n";
cin >> sel;
if (sel == "a" || sel == "A")
{
attack();
if (opponent.sta < 1)
{
break;
}
else if (player.tempsta < 1)
{
break;
}
else if (player.tempsta > 0 && opponent.sta > 0)
{
}
else
{
cout << "Error\n\n";
break;
}
}
else if (sel == "d" || sel == "D")
{
defend();
if (opponent.sta < 1)
{
break;
}
else if (player.tempsta < 1)
{
break;
}
else if (player.tempsta > 0 && opponent.sta > 0)
{
}
else
{
cout << "Error\n\n";
break;
}
}
else if (sel == "r" || sel == "R")
{
break;
}
else
{
cout << "Error\n\n";
break;
}
}
if (player.tempsta > 0 && opponent.sta <= 0)
{
player.exp += opponent.exp;
player.mon += opponent.mon;
player.tempsta = player.sta;
cout << "You gained " << opponent.mon << " money and " << opponent.exp << " experience points.\n";
exp();
}
else if (player.tempsta <=0 && opponent.sta > 0)
{
cout << "You lost the battle!\n";
}
else if (player.tempsta > 0 && opponent.sta > 0)
{
cout << "You escaped from the enemy.\n";
}
}
gamemenu() -- which calls battle()
Code:
void gamemenu() {
string opti;
while (opti != "e" || opti != "E")
{
cout << "Story Mode (press s)\nQuick Battle (press q)\nCharacter Info (press i)\nExit (press e)\n";
cin.ignore(100,'\n');
cin >> opti;
if (opti == "i" || opti == "I")
{
cout << "\nName: " << player.nam << "\nLevel: " << player.lev << "\nAttack: ";
cout << player.att << "\nDefense: " << player.def << "\nAgility: ";
cout << player.agi << "\nStamina: " << player.sta << "\nMoney: ";
cout << player.mon << "\nExperience: " << player.exp << "\n\n";
}
else if (opti == "q" || opti == "Q")
{
cout << endl;
battle();
cout << endl;
}
else if (opti == "e" || opti == "E")
{
cout << endl;
break;
}
else if (opti == "s" || opti == "S")
{
game();
}
}
}
EDIT: Oh, I forgot to post the struct containing the "player." and "opponent." variables. Here it is:
Code:
struct statistics {
string nam; //Name
int lev; //Level
int att; //Attack
int def; //Defense
int tempdef; //To heighten defense for a turn.
int agi; //Agility (not currrently used in the program)
int mon; //Money
int sta; //Stamina
int tempsta; //To keep track of player health while regenerating it after battle.
float gloc; //To keep track of your location in Story Mode.
float exp; //Experience (for leveling up, not currently used)
};