12 Replies - 371 Views - Last Post: 29 April 2013 - 05:29 AM Rate Topic: -----

#1 JimPickens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-February 13

Question about a small application I am coding

Posted 28 April 2013 - 09:28 AM

I am trying to code something like this http://betcalculator...rcalc/index.php in C#

I have created a form with multiple text boxes for the odds, a text box for the stake and one for the return.I have a calculate button with the following code in the click event.

 double Answer;

            double ans1 = 0.0;
            double ans2 = 0.0;
            double ans3 = 0.0;
            double ans4 = 0.0;
            double ans5 = 0.0;

            

            double myBet;
            myBet = double.Parse(txtStake.Text);

            double odds1;
            odds1 = double.Parse(txtBox1.Text);

            double odds2;
            odds2 = double.Parse(txtBox2.Text);

            double odds3;
            odds3 = double.Parse(txtBox3.Text);

            double odds4;
            odds4 = double.Parse(txtBox4.Text);
            
            double odds5;
            odds5 = double.Parse(txtBox5.Text);
            
            double odds6;
            odds6 = double.Parse(txtBox6.Text);
            
            double odds7;
            odds7 = double.Parse(txtBox7.Text);
            
            double odds8;
            odds8 = double.Parse(txtBox8.Text);
            
            double odds9;
            odds9 = double.Parse(txtBox9.Text);
            
            double odds10;
            odds10 = double.Parse(txtBox10.Text);




                   if (odds1 > 0)
                 ans1 = odds1 / odds2 * myBet + myBet;

                  if (odds3 > 0)
                 ans2 = odds3 / odds4 * myBet + myBet;

                  if (odds5 > 0)
                 ans3 = odds4 / odds5 * myBet + myBet;

                  if (odds7 > 0)
                 ans4 = odds6 / odds7 * myBet + myBet;

                  if(odds9 > 0) 
                 ans5 = odds8 / odds9 * myBet + myBet;


            Answer = ans1 + ans2 + ans3 + ans4 + ans5;

            txtReturn.Text = Answer.ToString();
            


Is This A Good Question/Topic? 0
  • +

Replies To: Question about a small application I am coding

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8399
  • View blog
  • Posts: 31,245
  • Joined: 12-June 08

Re: Question about a small application I am coding

Posted 28 April 2013 - 09:48 AM

... okay so what's the question?
Was This Post Helpful? 0
  • +
  • -

#3 JimPickens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-February 13

Re: Question about a small application I am coding

Posted 28 April 2013 - 09:55 AM

It's not returning the correct answers. I can' work out the formula to work out the correct answer.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8399
  • View blog
  • Posts: 31,245
  • Joined: 12-June 08

Re: Question about a small application I am coding

Posted 28 April 2013 - 09:59 AM

So explain how this formula is supposed to work.
Was This Post Helpful? 0
  • +
  • -

#5 JimPickens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-February 13

Re: Question about a small application I am coding

Posted 28 April 2013 - 10:21 AM

Ok.

There is a left column and a right column. These are for the betting odds. They are fractional.

The left column number is divided by the right column number and the answer to that is multiplied by the betting stake. That answer is then added to the original stake.

So, for example.

Posted Image

The return to this bet will be 18.00.

left column / right column * 2 = 4.

4 + 2 = 8.

8 * 2 = 16 + original stake of 2 = 18.

I just can't figure out to code this. I can do it in my head, just not in code, especially when it comes to doing multiple bets...

This post has been edited by JimPickens: 28 April 2013 - 10:22 AM

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8399
  • View blog
  • Posts: 31,245
  • Joined: 12-June 08

Re: Question about a small application I am coding

Posted 28 April 2013 - 10:38 AM

... and what sort of results are you getting (and the input)?
Was This Post Helpful? 0
  • +
  • -

#7 JimPickens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-February 13

Re: Question about a small application I am coding

Posted 28 April 2013 - 10:41 AM

If I use the above example. 2 stake at 2/1 and 2/1, I get a result of 12.
Was This Post Helpful? 0
  • +
  • -

#8 JimPickens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-February 13

Re: Question about a small application I am coding

Posted 28 April 2013 - 11:55 AM

I have it working correctly for two entries, but I can't do multiple bets.
Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Question about a small application I am coding

Posted 28 April 2013 - 12:12 PM

You've got the calculation wrong. The return from the first bet is the stake of the next bet, hence accumulator.

(2 / 1) * 2 + 2 = 6
(2 / 1) * 6 + 6 = 18
(4 / 3) * 18 + 18 = 42

So as a recursive function definition.
 f( n ) = ( F(n).L / F(n).R ) * F(n-1) + F(n-1) 
 f( 0 ) = stake

 F( n ).L ::= the left  hand side of that odds (eg the 2 of 2/1)
 F( n ).R ::= the right hand side of that odds (eg the 1 of 2/1)


Was This Post Helpful? 1
  • +
  • -

#10 JimPickens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-February 13

Re: Question about a small application I am coding

Posted 28 April 2013 - 12:40 PM

View PostAdamSpeight2008, on 28 April 2013 - 12:12 PM, said:

You've got the calculation wrong. The return from the first bet is the stake of the next bet, hence accumulator.

(2 / 1) * 2 + 2 = 6
(2 / 1) * 6 + 6 = 18
(4 / 3) * 18 + 18 = 42

So as a recursive function definition.
 f( n ) = ( F(n).L / F(n).R ) * F(n-1) + F(n-1) 
 f( 0 ) = stake

 F( n ).L ::= the left  hand side of that odds (eg the 2 of 2/1)
 F( n ).R ::= the right hand side of that odds (eg the 1 of 2/1)



Fantastic. Just what I was looking for. Thanks.
Was This Post Helpful? 0
  • +
  • -

#11 JimPickens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-February 13

Re: Question about a small application I am coding

Posted 28 April 2013 - 12:59 PM

Would this work better if I created an array of text boxes?
Was This Post Helpful? 0
  • +
  • -

#12 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Question about a small application I am coding

Posted 28 April 2013 - 01:10 PM

Why are thinking about textboxes at this stage?

Write a simple function to work out the return based only on the inputs of:- the odds and the stake.

Then write a function to calculate the accumulator return based only on the initial stake and different odds.

Question. Do you think odds be betters at its own object type?
Was This Post Helpful? 0
  • +
  • -

#13 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3183
  • View blog
  • Posts: 9,652
  • Joined: 05-May 12

Re: Question about a small application I am coding

Posted 29 April 2013 - 05:29 AM

This is the downside of drag and drop programming that MS and Borland originally espoused in the 80's and 90's. People tend to think of and use UI controls as variables, instead of actually having variables or objects as a model, and the UI controls as views on the model.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1