i wrote this up but seem to have done something wrong and honestly i cant seem to find it, it compiles just fine, but when i run i get stuck in an infinite loop.
my WHILE doesnt seem to be working, i know its to do with the variable STAMINA but im unsure how to get it to reduce from its originally stated value.
//$$---- Form CPP ----
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//Variables
int INIT_ENM_SKILL;
int CURR_PLAY_SKILL;
int ENM_Result;
int ENM_ATTK;
int DResult;
int PLAY_ATTK;
int STAMINA;
int ENM_STAMINA;
STAMINA=8;
ENM_STAMINA=7;
CURR_PLAY_SKILL=10;
INIT_ENM_SKILL=11;
//fight loop
do
{
//dice code
DResult = rand()%6 + rand()%6; //players dice rolls
ENM_Result = rand()%6 +rand()%6; //enemy dice rolls
//Determine opponent stats
ENM_ATTK=INIT_ENM_SKILL + ENM_Result; //enemy's attack number
//Determine Player stats
PLAY_ATTK=CURR_PLAY_SKILL + DResult; //players attack number
if (ENM_ATTK == PLAY_ATTK) //equal attck strength = miss
{
ShowMessage("Miss!");
}
else if (ENM_ATTK > PLAY_ATTK) // enemy attck strgth is higher
{
STAMINA -2;
ShowMessage("Enemy Attacks");
}
else if (ENM_ATTK < PLAY_ATTK) //players is higher
{
ENM_STAMINA -2;
ShowMessage("PLayer Attacks");
}
}
while (STAMINA || ENM_STAMINA != 0); // when players stamina OR enemy's hits 0, end
if (STAMINA ==0)
{
ShowMessage("Enemy WINS!");
exit(0);
}
else if (ENM_STAMINA==0)
{
ShowMessage("Player WINS!");
exit(0);
}
}
//---------------------------------------------------------------------------
thanks very much in advance