I have a little text based game i am working on.
The user has a few options of attack sometimes when the user presses “1” or jab the program just stops:
while(1)
{
if (round > 1) //First time no pause
Sleep(500); //Cleans up timing... i like it
score_round = 0;
//This is so ugly fix it!
printf("Round %d: \nChoose Your Attack:(1/2/.../D)\n\n1.Jab\t\tOr D to defend\n2.Cross\n3.Hook\n",round);
action = getch();
//Create the damage for each player
if(action == '1')
{
UserAttack = rand() % (UserStats[0]-2);
EnemyAttack = rand() % (EnemyStats[0]-3);
break;
}
else if(action == '2')
{
UserAttack = rand() %UserStats[0];
EnemyAttack = rand() %EnemyStats[0];
break;
}
else if(action == '3')
{
UserAttack = rand() %(UserStats[0]+4);
EnemyAttack = rand() %(EnemyStats[0]+2);
break;
}
else if(action == 'D' || action == 'd')
{
UserAttack= 0;
EnemyAttack = defense(); //Defense randomizes a number upto 3 if it is 1 the enemy attack is 1 point
break;
}
else //Ensures the key pressed is a valid choice
{
system("cls");
printf("INVALID ACTION PRESS ANY KEY TO RECHOOSE:"); getch(); //TODO: Pressing this clears the health screen!
system("cls"); //Clears screen just in case
continue;
}
}
I ran the debugger and all the variables were fine but call stack (which i do not know about returned this)

If you need more info let me know! Thank you!
You could have a low value for userstats or enemystats, causing the expression
to be zero. This results in taking something mod 0, which is bad.
You might use something like
to get the behavior you want.