Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8239451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:09:15+00:00 2026-06-07T20:09:15+00:00

I have a little text based game i am working on. The user has

  • 0

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)

Call Stack

If you need more info let me know! Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:09:17+00:00Added an answer on June 7, 2026 at 8:09 pm

    You could have a low value for userstats or enemystats, causing the expression

    EnemyStats[0]-3
    

    to be zero. This results in taking something mod 0, which is bad.

    You might use something like

    x ? y%x : x
    

    to get the behavior you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a little text-based game after watching the new Tron movie
I have several text fields that are dynamically populated based on user choice from
I have this little text <div> Hello world<br> this is a good<br> text! <br><br>
I have little question about how web browser retrieve webpage? I know this User
I have a J2EE/JSF-based web-app. It consists of an form-input, a text display and
I have a website based on GAE and Python, and I'd like the user
I'm writing an app to view an online web text-based game. I want to
I have a C# WinForm program that is essentially a glorified text parser. It
A simulation program I'm using requires a text based input file. I need to
I am trying to make an interactive, text-based connect4 game in SWI Prolog, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.