10 Replies - 709 Views - Last Post: 04 April 2016 - 12:35 PM Rate Topic: -----

#1 Benniehat   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-April 16

Help Needed! How would you code this?

Posted 04 April 2016 - 09:46 AM

Need to code this for college but need some help, just wondering if there was someone could enlighten me lol



Win amount = Backstake * Backodds

Laystake = [BookieWinAmount] / ([LayOdds] - ([LayCommission]/100))

Liability = (layodds - 1) * laystake

Profit = laystake - backstake

Attached image(s)

  • Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: Help Needed! How would you code this?

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 16479
  • View blog
  • Posts: 65,313
  • Joined: 12-June 08

Re: Help Needed! How would you code this?

Posted 04 April 2016 - 09:47 AM

What is your question, or would you be more specific on what you need help with.
Was This Post Helpful? 0
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 793
  • View blog
  • Posts: 5,089
  • Joined: 12-January 10

Re: Help Needed! How would you code this?

Posted 04 April 2016 - 09:57 AM

looks like you need dropdown
text boxes
buttons
prob some methods on calculations
some input variables
prob some output variables
some code here and there
Was This Post Helpful? 0
  • +
  • -

#4 Benniehat   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-April 16

Re: Help Needed! How would you code this?

Posted 04 April 2016 - 10:01 AM

View Postmodi123_1, on 04 April 2016 - 09:47 AM, said:

What is your question, or would you be more specific on what you need help with.


Well I am trying simply to multiply the backstake and backodds texbox values to get the "Win amount".

This works but only if the values entered aren't decimal which is what I am needing it to do.

Thanks

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 16479
  • View blog
  • Posts: 65,313
  • Joined: 12-June 08

Re: Help Needed! How would you code this?

Posted 04 April 2016 - 10:09 AM

So a few things. Instead of going through taking screen shots just copy the text and paste it here (make sure to use the 'code' tag button in the editor).

Second - if you want decimals then perhaps don't use integers. Those are nothing but whole numbers.
Was This Post Helpful? 0
  • +
  • -

#6 Curtis Rutland   User is offline

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Help Needed! How would you code this?

Posted 04 April 2016 - 10:14 AM

Two things: use the Parse/TryParse functions on the numeric types (int.TryParse, double.TryParse) rather than the Convert class. More explicit, less confusion.

Second: the int keyword means "an integer number". Integers don't have decimal places. If you want those, use double.
Was This Post Helpful? 0
  • +
  • -

#7 Benniehat   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-April 16

Re: Help Needed! How would you code this?

Posted 04 April 2016 - 11:02 AM

View PostCurtis Rutland, on 04 April 2016 - 10:14 AM, said:

Two things: use the Parse/TryParse functions on the numeric types (int.TryParse, double.TryParse) rather than the Convert class. More explicit, less confusion.

Second: the int keyword means "an integer number". Integers don't have decimal places. If you want those, use double.


Ok it can now calculate the laystake, but there is an error with the liability calculation.

            double BS;
            double BO;
            double winnings;
            double laystake;
            double liability;
            double LO;
            double LC;
            double LS;

            BS = double.Parse(txtBS.Text);
            BO = double.Parse(txtBO.Text);
            LO = double.Parse(txtLO.Text);
            LC = double.Parse(txtLC.Text);
            LS = double.Parse(txtLS.Text);

            winnings = BS * BO;
            laystake = (winnings / (LO - (LC / 100)));
            liability = ((LO - 1) * LS);

            txtLS.Text = laystake.ToString();
            txtL.Text = liability.ToString();


Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 16479
  • View blog
  • Posts: 65,313
  • Joined: 12-June 08

Re: Help Needed! How would you code this?

Posted 04 April 2016 - 11:03 AM

Use tryparse and also verify what is the value of that textbox.
Was This Post Helpful? 0
  • +
  • -

#9 Curtis Rutland   User is offline

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Help Needed! How would you code this?

Posted 04 April 2016 - 11:37 AM

"Input string was not in the correct format" seems pretty straight-forward: the input string (the string you're trying to convert) is not in the correct format (meaning it's not a number, or not a string that can be converted into a number).
Was This Post Helpful? 0
  • +
  • -

#10 Benniehat   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-April 16

Re: Help Needed! How would you code this?

Posted 04 April 2016 - 12:26 PM

View PostCurtis Rutland, on 04 April 2016 - 11:37 AM, said:

"Input string was not in the correct format" seems pretty straight-forward: the input string (the string you're trying to convert) is not in the correct format (meaning it's not a number, or not a string that can be converted into a number).


Thats it pretty much working now, only issue is how to round the values in the profit,liability and laystake textboxes to 2 decimal places?


            double BS;
            double BO;
            double LO;
            double LC;
            double winnings;
            double laystake;
            double liability;

            BS = double.Parse(txtBS.Text);
            BO = double.Parse(txtBO.Text);
            LO = double.Parse(txtLO.Text);
            LC = double.Parse(txtLC.Text);
          

            winnings = BS * BO;
            laystake = (winnings / (LO - (LC / 100)));
            liability = ((LO - 1) * laystake);

            txtLS.Text = laystake.ToString();
            txtL.Text = liability.ToString();
            txtPROFIT.Text = (laystake - BS - ((laystake/100)*LC)).ToString();



Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#11 Curtis Rutland   User is offline

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Help Needed! How would you code this?

Posted 04 April 2016 - 12:35 PM

Quote

only issue is how to round the values in the profit,liability and laystake textboxes to 2 decimal places


Google "C# Rounding". Gotta learn how to do some of this yourself too.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1