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 6348461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:25:23+00:00 2026-05-24T21:25:23+00:00

I am having a problem with my code below. When the user selects a

  • 0

I am having a problem with my code below. When the user selects a RadioButton (such as reload) and clicks the submit button, I want an ammo counter in the screen to increase by 1. On a RadioButton selection of “fire”, I want the ammo counter to decrease by one.

The problem I’m having is the ammo counter seems to be one behind the user selection. So:

  • ammo count = 1: user selects reload
  • ammo count = 1: user selects
    reload
  • ammo count = 2: user selects fire
  • ammo count = 3: user selects
    reload
  • ammo count = 2:

^^ see, the ammo count is consistently one behind the user selection. How can I fix this?

   namespace ShotgunApp
{
    public partial class SingleGame : PhoneApplicationPage
    {
        public static class AmmoCount
        {
            public static int userAmmo = startVars.startAmmo;
            public static int geniusAmmo = startVars.startAmmo;
        }


        public SingleGame()
        {
            InitializeComponent();
            GeniusAmmo.Text = "ammo: " + AmmoCount.geniusAmmo;
            UserAmmo.Text = "ammo: " + AmmoCount.userAmmo;


        }

        private void submit_Click(object sender, RoutedEventArgs e)
        {
            Move();
        }

        public void Move()
        { 
            if (uReload.IsChecked.HasValue && uReload.IsChecked.Value == true)
            {
                UserAmmo.Text = "ammo: " + AmmoCount.userAmmo++;

            }
            else if (uShield.IsChecked.HasValue && uShield.IsChecked.Value == true)
            {

            }
            else if (uFire.IsChecked.HasValue && uFire.IsChecked.Value == true)
            {
                UserAmmo.Text = "ammo: " + AmmoCount.userAmmo--;
            }
            else
            {

            }
        }
    }
}
  • 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-05-24T21:25:25+00:00Added an answer on May 24, 2026 at 9:25 pm

    AmmoCount.userAmmo++ and AmmoCount.userAmmo-- (postfix operators) are decrementing and incrementing the variable correctly but they return the previous unchanged values.

    You should use the prefix operators: (++AmmoCount.userAmmo) and (--AmmoCount.userAmmo).

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

Sidebar

Related Questions

Having a problem getting a TreeView control to display node images. The code below
I'm having kind of a dumb problem. I am using the below code to
I have a very specific problem. I have a user control (code below) That
I am having a problem with the below code and I am not sure
I am having this problem in below code as my ArrayList both name and
I'm having a problem with my Seam code and I can't seem to figure
I am trying to convert this test code to C# and having a problem
I am having some trouble with this code . The problem is when i
I am having a problem while sending mails through code.Actually the code is running
I want to have sum of values in a dict. Below is the code

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.