none
Problem with INT RRS feed

  • Question

  • Hey, I'm trying to do a button that <g class="gr_ gr_101 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="101" id="101">everytime</g> you click on him its double the number value (money value).

    But, there is a catch, I use random to random an event that Reset the Value to 1.

    I got a problem with the code, he is working well sometimes and sometimes doesn't to the math good. (I create saved <g class="gr_ gr_73 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="73" id="73">moneybalance</g> that located and count your money balance and every time you push the button that adds <g class="gr_ gr_89 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="89" id="89">your money</g> that you achieve from pressing the button to the correct balance but its sometimes do a wrong math and sometimes its reset the value or do a something that <g class="gr_ gr_148 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="148" id="148">make</g> the Balance less.

    I'm <g class="gr_ gr_194 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="194" id="194">beginner</g> so I think the code it's not so complicated but I hope you can help me to find my bug.

    Thank you <3

    Thank you <3


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApp1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            int t1; //value in the button
    
            int balance; //balance from the button
    
            int a; //random_num
    
            int savedbalance; //currect balance, (He gets 
             +_balance with click on button)
    
            public MainWindow()
            {
                InitializeComponent();
                t1 = 1;
                Money.FontSize = 72; //money= labelname
                Money.FontWeight = FontWeights.Bold;
    
            }
    
    
    
            private void CB_Click_1(object sender, RoutedEventArgs e)
            {
                Random r = new Random();
                int a = r.Next(1, 100);
                te.Content = a;
    
                if (a<90)
                {
                    if (t1 < 1000)
                    {
                        Money.Content = t1;
                        t1 = t1 + t1;
                    }
                    else
                    {
                        Money.FontSize = 50;
                        Money.Content = t1;
                        t1 = t1 + t1;
                    }
                } else
                {
                    t1 = 1;
                    Money.Content = t1;
    
                }
    
    
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
           
                    balance = t1 / 2;
                    MonBalance.FontSize = 35; //saved balance 
                    label name
                    MonBalance.Content = savedbalance + 
                    balance;
                    Money.FontWeight = FontWeights.Bold;
                    savedbalance = balance;
                    t1 = 1;
                
    
    
    
    
            }
        }
    }


    • Edited by MesikaX Sunday, October 21, 2018 9:33 PM
    Sunday, October 21, 2018 9:29 PM

All replies

  • Hey, <g class="gr_ gr_13 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="13" id="13">im</g> trying to do <g class="gr_ gr_197 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="197" id="197">button</g> that everytime you click on him its double the number value (money value).

    But, there is a catch, I use random to random an event that Reset the Value to 1.

    I got a problem with the code, he is working well sometimes and sometimes <g class="gr_ gr_411 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="411" id="411">dont</g> to the math <g class="gr_ gr_438 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="438" id="438">good</g>. (I create saved <g class="gr_ gr_484 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="484" id="484">moneybalance</g> that located and count your money balance and <g class="gr_ gr_689 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="689" id="689">everytime</g> you push the button that <g class="gr_ gr_687 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="687" id="687">add</g> <g class="gr_ gr_734 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="734" id="734">your money</g> that you <g class="gr_ gr_722 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="722" id="722">acihve</g> from pressing the button to the <g class="gr_ gr_781 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="781" id="781">currect</g> balance but its sometimes do a wrong math and <g class="gr_ gr_952 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="952" id="952">somethimes</g> its reset the value or do a <g class="gr_ gr_1057 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="1057" id="1057">someting</g> that make the Balance less.

    <g class="gr_ gr_1173 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="1173" id="1173">Im</g> <g class="gr_ gr_1177 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="1177" id="1177">begginer</g> <g class="gr_ gr_1184 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" data-gr-id="1184" id="1184">so <g class="gr_ gr_1218 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="1218" id="1218">i</g></g> think the code <g class="gr_ gr_1217 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="1217" id="1217">its</g> not so complicated but <g class="gr_ gr_1312 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="1312" id="1312">i</g> hope you can help me to find my bug.

    Thank you <3

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApp1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            int t1; //value in the button
    
            int balance; //balance from the button
    
            int a; //random_num
    
            int savedbalance; //currect balance, (He gets 
             +_balance with click on button)
    
            public MainWindow()
            {
                InitializeComponent();
                t1 = 1;
                Money.FontSize = 72; //money= labelname
                Money.FontWeight = FontWeights.Bold;
    
            }
    
    
    
            private void CB_Click_1(object sender, RoutedEventArgs e)
            {
                Random r = new Random();
                int a = r.Next(1, 100);
                te.Content = a;
    
                if (a<90)
                {
                    if (t1 < 1000)
                    {
                        Money.Content = t1;
                        t1 = t1 + t1;
                    }
                    else
                    {
                        Money.FontSize = 50;
                        Money.Content = t1;
                        t1 = t1 + t1;
                    }
                } else
                {
                    t1 = 1;
                    Money.Content = t1;
    
                }
    
    
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
           
                    balance = t1 / 2;
                    MonBalance.FontSize = 35; //saved balance 
                    label name
                    MonBalance.Content = savedbalance + 
                    balance;
                    Money.FontWeight = FontWeights.Bold;
                    savedbalance = balance;
                    t1 = 1;
                
    
    
    
    
            }
        }
    }
    

    Sunday, October 21, 2018 9:29 PM
  • Hi,

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApp1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            int t1; //value in the button
    
            int balance; //balance from the button
    
            int a; //random_num
    
            int savedbalance; //currect balance, (He gets 
             +_balance with click on button)
    
            Random r;
    
            public MainWindow()
            {
                InitializeComponent();
                t1 = 1;
                Money.FontSize = 72; //money= labelname
                Money.FontWeight = FontWeights.Bold;
                r = new Random();
            }
    
            private void CB_Click_1(object sender, RoutedEventArgs e)
            {
                int a = r.Next(1, 100);
                te.Content = a;
    
                if (a < 90)
                {
                    if (t1 < 1000)
                    {
                        Money.Content = t1;
                        t1 = t1 + t1;
                    }
                    else
                    {
                        Money.FontSize = 50;
                        Money.Content = t1;
                        t1 = t1 + t1;
                    }
                }
                else
                {
                    t1 = 1;
                    Money.Content = t1;
    
                }
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
    
                balance = t1 / 2;
                MonBalance.FontSize = 35; //saved balance 
                label name
                    MonBalance.Content = savedbalance +
                    balance;
                Money.FontWeight = FontWeights.Bold;
                savedbalance = balance;
                t1 = 1;
            }
        }
    }

    Greetings, Chris


    • Edited by DerChris88 Sunday, October 21, 2018 9:39 PM
    Sunday, October 21, 2018 9:35 PM
  • Hi Mesikak,

    Thank you for posting here.

    >>But, there is a catch, I use random to random an event that Reset the Value to 1.

    In your code, how do you reset the value to 1? Based on my test, you use random to get value of a. It is possible when 90<a<100,it would not reset the value to 1.

    Please check the condition of if statement.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 22, 2018 3:26 AM
    Moderator
  • Maybe you should change the order of instructions to:

       t1 = t1 + t1;
       Money.Content = t1;

    Also note that if t1 is 1, then ‘balance = t1 / 2’ will be zero.


    Monday, October 22, 2018 4:49 AM
  • I will try to change the order.

    And Thank you!

    Monday, October 22, 2018 8:12 PM
  • Oh really thank you!
    Monday, October 22, 2018 8:23 PM
  • Hi MesikaX,

    If your question has been solved, please mark the useful reply as answer to close the thread. This will make answer searching easier in the forum and be beneficial to community members as well.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, October 23, 2018 3:22 AM
    Moderator