well this may be a simple problem for most to solve i can't seem to solve it.
int damagee(int dragon, int swordattack) --> The function
{
int s;
s = dragon - swordattack;
std::cout<<s;
}
int main (int argc, char * const argv[]) {
using std::cout;
using std::cin;
using std::string;
using namespace std;
//Variables
int swordattack,dragon; --> the variable is defined
dragon = 300;
swordattack = 20;
string start;
start = "start";
if(battlemen == attack)
{
cout<<"You pull Your Mighty Sword out and slice the dragons scales";
dragon = damagee(dragon,swordattack);
continue;
}
EXECUTION --
*BATTLE MENU*
1.Attack
2.Magic
3.Defend
1
You pull Your Mighty Sword out and slice the dragons scales280*****************
*BATTLE MENU* ====> WORKS THE FIRST TIME!!
1.Attack
2.Magic
3.Defend
1
You pull Your Mighty Sword out and slice the dragons scales-1604102932***************** ------> WHY AM I GETTING THIS THE SECOND??
*BATTLE MENU*
1.Attack
2.Magic
3.Defend
//submenu magic functions
void submagic()
{
using std::cout;
using std::cin;
cout<<"1. White Magic\n";
cout<<"2. Black Magic\n";
cout<<"3. Back\n";
}
//damage report enemy
int damagee(int dragon)
{
std::cout<<"*Enemy has "<<dragon<<" HP left*";
}
int main (int argc, char * const argv[]) {
using std::cout;
using std::cin;
using std::string;
using namespace std;
//Variables
string start;
start = "start";
//attack main menus
int attack,magic,defend,battlemen;
attack = 1;
magic = 2;
defend = 3;
//attack actions
int swordattack;
swordattack = 20;
//monsters hp
int dragon;
dragon = 320;
//Hero
int hero;
hero = 130;
//game start
cout<<"RPG battle Test C++";
cout<<"To Fight type 'battle' to end type 'end': ";
cin>>start;
if(start == start)
{
cout<<"A Enemy Dragon Approaches!"<<endl;
}
//program loop
for(;;)
{
//attack menu
cout<<"*****************\n";
cout<<"*BATTLE MENU*\n";
cout<<"1.Attack\n";
cout<<"2.Magic\n";
cout<<"3.Defend\n";
cin>>battlemen;
if(battlemen == attack)
{
cout<<"You pull Your Mighty Sword out and slice the dragons scales";
dragon = dragon - swordattack; //works for the first time
*BATTLE MENU*
1.Attack
2.Magic
3.Defend
1
You pull Your Mighty Sword out and slice the dragons scales280*****************
*BATTLE MENU* ====> WORKS THE FIRST TIME!!
1.Attack
2.Magic
3.Defend
1
You pull Your Mighty Sword out and slice the dragons scales-1604102932***************** ------> WHY AM I GETTING THIS THE SECOND??
*BATTLE MENU*
1.Attack
2.Magic
3.Defend
I have XCode as well. 3.2.2. I plug this code in, and notice several things.
1. It compiles.
2. If you type "end", it continues to the battle. In fact, type anything and you battle.
3. It compiles.
4. Your menus are broken. Using Magic ends the game, and using Attack does not display the dragon's HP, unlike in your output. Forgot a function or two for that one? Magic ends the game because of the break; statement. You don't need it, you don't want it, unless you want magic to work perfectly.
5. Your submagic() doesn't make use of cin.
6. The dragon becomes a zombie after you hit it 16 times. It's health goes negative, and yet ITS ALIVE! O.o
7. It compiles.
EDIT: 8. The error you mentioned does not occur with what you give me.