I'm pretty low-level at C++, but decided writing up a program to do some playtesting work for me would save a lot of time. Anyway, I'm almost done - been debugging for a little while, and I've managed to bring it down to 16 repeats of the same two errors...and I get the impression that the illegal breaks are a result of the illegal cases.
I've looked at various help threads throughout the web for these errors, but I still haven't been able to figure it out.
/* This is a playtesting program for Abnormous Attire. Rebuild and run each time
the statistics are changed, and attempt to balance all the result numbers.
The only things that should be changed on rebuild are the attribute variables.
This is build 1*/
#include <iostream>
using namespace std;
//Declaring the variables used for player 1 and 2's stats
int hp, hp2, style, style2, pants, pants2, action, action2, elemental, elemental2, atk, atk2, actioncost, actioncost2, act, act2;
//Element-based attributes
int b_style = 25, b_pants = 20, b_action = 1;//Body
int e_style = 20, e_pants = 25, e_action = 1;//Earth
int f_style = 45, f_pants = 10, f_action = 1;//Fire
int w_style = 30, w_pants = 20, w_action = 2;//Wind
//Job-based attributes
int k_pants = 20, k_style = 0, k_action = 1;//Knight
int m_pants = 0, m_style = 20, m_action = 1;//Mage
int t_pants = 0, t_style = 10, t_action = 2;//Thief
//Display and recording variables
int k_wins, m_wins, t_wins, b_wins, e_wins, f_wins, w_wins, dualinvince;
int kb_wins, ke_wins, kf_wins, kw_wins;
int mb_wins, me_wins, mf_wins, mw_wins;
int tb_wins, te_wins, tf_wins, tw_wins;
int p1_wins, p2_wins;
int display, skipdisp;
int error (int ele, int ele2, int job, int job2)
{
cout<<"An error has occured; element is "<<ele<<", element2 is "<<ele2<<","<<endl;
cout<<"job is "<<job<<", and job2 is "<<job2<<"."<<endl;
return 0;
}
//Checks temporary win record for element and job, and makes permanent record
int record (int wjob, int wjob2, int wele, int wele2)
{
if (p1_wins==1)
{
if (wjob==1)
{
k_wins += 1;
if (wele==1)
{
b_wins +=1;
kb_wins +=1;
}
if (wele==2)
{
e_wins +=1;
ke_wins +=1;
}
if (wele==3)
{
f_wins +=1;
kf_wins +=1;
}
if (wele==4)
{
w_wins +=1;
kw_wins +=1;
}
}
if (wjob==2)
{
m_wins += 1;
if (wele==1)
{
b_wins +=1;
mb_wins +=1;
}
if (wele==2)
{
e_wins +=1;
me_wins +=1;
}
if (wele==3)
{
f_wins +=1;
mf_wins +=1;
}
if (wele==4)
{
w_wins +=1;
mw_wins +=1;
}
}
if (wjob==3)
{
t_wins += 1;
if (wele==1)
{
b_wins +=1;
tb_wins +=1;
}
if (wele==2)
{
e_wins +=1;
te_wins +=1;
}
if (wele==3)
{
f_wins +=1;
tf_wins +=1;
}
if (wele==4)
{
w_wins +=1;
tw_wins +=1;
}
}
}
if (p2_wins==1)
{
if (wjob2==1)
{
k_wins += 1;
if (wele2==1)
{
b_wins +=1;
kb_wins +=1;
}
if (wele2==2)
{
e_wins +=1;
ke_wins +=1;
}
if (wele2==3)
{
f_wins +=1;
kf_wins +=1;
}
if (wele2==4)
{
w_wins +=1;
kw_wins +=1;
}
}
if (wjob2==2)
{
m_wins += 1;
if (wele2==1)
{
b_wins +=1;
mb_wins +=1;
}
if (wele2==2)
{
e_wins +=1;
me_wins +=1;
}
if (wele2==3)
{
f_wins +=1;
mf_wins +=1;
}
if (wele2==4)
{
w_wins +=1;
mw_wins +=1;
}
}
if (wjob2==3)
{
t_wins += 1;
if (wele2==1)
{
b_wins +=1;
tb_wins +=1;
}
if (wele2==2)
{
e_wins +=1;
te_wins +=1;
}
if (wele2==3)
{
f_wins +=1;
tf_wins +=1;
}
if (wele2==4)
{
w_wins +=1;
tw_wins +=1;
}
}
}
p1_wins = p2_wins = 0; //Resetting temporary player win counter
return 0;
}
int battle (int element, int element2)
{
int turns, turns2, typcha, typcha2, invince, invince2;
atk = style + elemental - pants2;
atk2 = style2 + elemental2 - pants;
actioncost = actioncost2 = 2;
//Script to determine attack type and damage for player 1
if (elemental==-10)
{
atk += 5;
typcha = 1;
}
if (atk <= 0)
{
if (typcha!=1)
{
if (atk > -5)
{
actioncost = 4;
atk += 5;
typcha = 1;
}
else
{
invince2 = 1;
}
}
}
if (element==1)
{
if (atk > 5)
{
if (typcha!=1)
{
actioncost = 1;
atk -= 5;
}
}
}
typcha = 0; //Resetting typcha
//Script to determine attack type and damage for player 2
if (elemental2==-10)
{
atk2 += 5;
typcha2 = 1;
}
if (atk2 <= 0)
{
if (typcha2!=1)
{
if (atk2 > -5)
{
actioncost2 = 4;
atk2 += 5;
typcha2 = 1;
}
else
{
invince = 1;
}
}
}
if (element2==1)
{
if (atk2 > 5)
{
if (typcha2!=1)
{
actioncost2 = 1;
atk2 -= 5;
}
}
}
typcha2 = 0; //Resetting typcha2
//Runs an invincibility check, to pre-empt infinite loops
switch (invince)
case 1:
switch (invince2)
case 0:
p1_wins = 1;
break; //<------------------------------------------- Illegal break here
case 1: //<---------------------------------------------- Illegal case here
dualinvince += 1;
break; //<------------------------------------------- Illegal break here
break; //<--------------------------------------------------- Illegal break here
case 0: //<------------------------------------------------------ Illegal case here
switch (invince2)
case 1:
p2_wins = 1;
break; //<------------------------------------------- Illegal break here
case 0: //<---------------------------------------------- Illegal case here
//Runs a loop to determine number of turns player 1 takes to defeat player 2
for (hp2 = 100, act = action, turns = 0; hp2 > 0; act += action)
{
if (act >= actioncost)
{
hp2 -= atk;
act -= actioncost;
}
turns++;
}
//Runs a loop to determine number of turns player 2 takes to defeat player 1
for (hp = 100, act2 = action2, turns2 = 0; hp > 0; act2 += action2)
{
if (act2 >= actioncost2)
{
hp -= atk2;
act2 -= actioncost2;
}
turns2++;
}
//Checks battle results and applies wins
if (turns>=turns2)
{
p1_wins = 1;
}
if (turns<turns2)
{
p2_wins = 1;
}
break; //<----------------------------------------- Illegal break here
invince = invince2 = 0; //Resetting invince and invince2
return 0;
}
int jobfunc (int job, int job2, int element, int element2)
{
if (job==1)
{
style += k_style; pants += k_pants; action += k_action;
}
else if (job==2)
{
style += m_style; pants += m_pants; action += m_action;
}
else if (job==3)
{
style += t_style; pants += t_pants; action += t_action;
}
else
{
error (40, 40, job, job2);
}
if (job2==1)
{
style2 += k_style; pants2 += k_pants; action2 += k_action;
}
else if (job2==2)
{
style2 += m_style; pants2 += m_pants; action2 += m_action;
}
else if (job2==3)
{
style2 += t_style; pants2 += t_pants; action2 += t_action;
}
else
{
error (41, 41, job, job2);
}
battle (element, element2);
return 0;
}
int elementalf (int element, int element2)
{
//Determining element of each player, in order to pass along elemental modifier and base stats
if (element==1)
{
elemental = elemental2 = 0;
style += b_style; pants += b_pants; action += b_action;
if (element2==1)
{
style2 += b_style; pants2 += b_style; action2 += b_action;
}
else if (element2==2)
{
style2 += e_style; pants2 += e_pants; action2 += e_action;
}
else if (element2==3)
{
style2 += f_style; pants2 += f_pants; action2 += f_action;
}
else if (element2==4)
{
style2 += w_style; pants2 += w_pants; action2 += w_action;
}
else
{
error (element, element2, 20, 20);
}
}
else if (element==2)
{
style += e_style; pants += e_pants; action += e_action;
if (element2==1)
{
elemental = elemental2 = 0;
style2 += b_style; pants2 += b_pants; action2 += b_action;
}
else if (element2==2)
{
elemental = elemental2 = 0;
style2 += e_style; pants2 += e_pants; action2 += e_action;
}
else if (element2==3)
{
elemental = 5;
elemental2 = -10;
style2 += f_style; pants2 += f_pants; action2 += f_action;
}
else if (element2==4)
{
elemental = -10;
elemental2 = 5;
style2 += w_style; pants2 += w_pants; action2 += w_action;
}
else
{
error (element, element2, 21, 21);
}
}
else if (element==3)
{
style += f_style; pants += f_pants; action += f_action;
if (element2==1)
{
elemental = elemental2 = 0;
style2 += b_style; pants2 += b_pants; action2 += b_action;
}
else if (element2==2)
{
elemental = -10;
elemental2 = 5;
style2 += e_style; pants2 += e_pants; action2 += e_action;
}
else if (element2==3)
{
elemental = elemental2 = 0;
style2 += f_style; pants2 += f_pants; action2 += f_action;
}
else if (element2==4)
{
elemental = 5;
elemental2 = -10;
style2 += w_style; pants2 += w_pants; action2 += w_action;
}
else
{
error (element, element2, 22, 22);
}
}
else if (element==4)
{
style += w_style; pants += w_pants; action += w_action;
if (element2==1)
{
elemental = elemental2 = 0;
style2 += b_style; pants2 += b_pants; action2 += b_action;
}
else if (element2==2)
{
elemental = 5;
elemental2 = -10;
style2 += e_style; pants2 += e_pants; action2 += e_action;
}
else if (element2==3)
{
elemental = -10;
elemental2 = 5;
style2 += f_style; pants2 += f_pants; action2 += f_action;
}
else if (element2==4)
{
elemental = elemental2 = 0;
style2 += w_style; pants2 += w_pants; action2 += w_action;
}
else
{
error (element, element2, 23, 23);
}
}
else
{
error (element, element2, 24, 24);
}
jobfunc (1, 1, element, element2);
record (1, 1, element, element2);
jobfunc (1, 2, element, element2);
record (1, 2, element, element2);
jobfunc (1, 3, element, element2);
record (1, 3, element, element2);
jobfunc (2, 1, element, element2);
record (2, 1, element, element2);
jobfunc (2, 2, element, element2);
record (2, 2, element, element2);
jobfunc (2, 3, element, element2);
record (2, 3, element, element2);
jobfunc (3, 1, element, element2);
record (3, 1, element, element2);
jobfunc (3, 2, element, element2);
record (3, 2, element, element2);
jobfunc (3, 3, element, element2);
record (3, 3, element, element2);
return 0;
}
int main ()
{
elementalf (1, 1);
elementalf(1, 2);
elementalf (1, 3);
elementalf (1, 4);
elementalf (2, 1);
elementalf (2, 2);
elementalf (2, 3);
elementalf (2, 4);
elementalf (3, 1);
elementalf (3, 2);
elementalf (3, 3);
elementalf (3, 4);
elementalf (4, 1);
elementalf (4, 2);
elementalf (4, 3);
elementalf (4, 4);
menu:
cout << "Finished calculating and recording results."<<endl;
cout << "What would you like to view?"<<endl;
cout << "1. All results."<<endl;
cout << "2. Class win results."<<endl;
cout << "3. Element win results."<<endl;
cout << "4. Individual win results."<<endl;
cout << "5. Exit."<<endl;
cin >> display;
switch (display)
case 1:
skipdisp = 1;
case 2: //<--------------------------------------- Illegal case here
cout << "Knight: "<<k_wins<<endl;
cout << "Mage: "<<m_wins<<endl;
cout << "Thief: "<<t_wins<<endl;
if (skipdisp != 1)
goto menu;
case 3: //<--------------------------------------- Illegal case here
cout << "Body: "<<b_wins<<endl;
cout << "Earth: "<<e_wins<<endl;
cout << "Fire: "<<f_wins<<endl;
cout << "Wind: "<<w_wins<<endl;
if (skipdisp != 1)
goto menu;
case 4: //<--------------------------------------- Illegal case here
cout << "Body; Knight, Mage, Thief: "<<kb_wins<<", "<<mb_wins<<", "<<tb_wins<<endl;
cout << "Earth; Knight, Mage, Thief: "<<ke_wins<<", "<<me_wins<<", "<<te_wins<<endl;
cout << "Fire; Knight, Mage, Thief: "<<kf_wins<<", "<<mf_wins<<", "<<tf_wins<<endl;
cout << "Wind; Knight, Mage, Thief: "<<kw_wins<<", "<<mw_wins<<", "<<tw_wins<<endl;
skipdisp = 0;
goto menu;
break; //<------------------------------------ Illegal break here
case 5: //<--------------------------------------- Illegal case here
break; //<------------------------------------ Illegal break here
return 0;
}
And the errors I'm getting:
1>cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release
1>Fighter.cpp
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(273) : error C2043: illegal break
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(274) : error C2046: illegal case
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(276) : error C2043: illegal break
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(277) : error C2043: illegal break
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(278) : error C2046: illegal case
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(282) : error C2043: illegal break
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(283) : error C2046: illegal case
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(313) : error C2043: illegal break
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(529) : error C2046: illegal case
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(535) : error C2046: illegal case
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(542) : error C2046: illegal case
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(549) : error C2043: illegal break
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(550) : error C2046: illegal case
1>c:\users\administrator\documents\c++\fight\fight\fighter.cpp(551) : error C2043: illegal break
Thanks in advance for any help. I'd keep looking things up rather than make a post, but I really need to get this done soon.