Jump to content

Lotto Program Maths Problem.


Recommended Posts

hello all,

I need help im making a simple lotto program that also tell you how much each price is as well but my maths is letting me down can you have a look and currect my maths.

in the input box if you put 100 for 100 pounds you can see were my probelm is and i have put in the code the crect answers well i think please have a look.

OOOOO secound of all how can you valadate a input box to just be numbers only please thanks.

thanks all.

program code here.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 314, 410, 192, 124)
$Label1 = GUICtrlCreateLabel("LOTTO PROGRAM", 72, 24, 155, 24)
GUICtrlSetFont(-1, 12, 800, 4, "MS Sans Serif")

$Group1 = GUICtrlCreateGroup("1st Prize", 8, 72, 89, 209)
$Label3 = GUICtrlCreateLabel("Money Prize", 24, 216, 62, 17)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("", 32, 136, 39, 17)
$Label9 = GUICtrlCreateLabel("", 32, 232, 44, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group2 = GUICtrlCreateGroup("2nd Prize", 112, 72, 89, 209)
$Label4 = GUICtrlCreateLabel("Money Prize", 126, 213, 62, 17)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
$Label7 = GUICtrlCreateLabel("", 133, 135, 39, 17)
$Label10 = GUICtrlCreateLabel("", 136, 232, 42, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group3 = GUICtrlCreateGroup("3rd Prize", 216, 72, 89, 209)
$Label5 = GUICtrlCreateLabel("Money Prize", 228, 212, 62, 17)
GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
$Label8 = GUICtrlCreateLabel("", 240, 136, 39, 17)
$Label11 = GUICtrlCreateLabel("", 240, 232, 42, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$Input1 = GUICtrlCreateInput("number", 96, 328, 121, 21)
$Label2 = GUICtrlCreateLabel("Total Prize Money", 112, 304, 89, 17)
$Button1 = GUICtrlCreateButton("Run Lotto", 120, 360, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Button1
                Randomnumber()
                money()
        EndSwitch
WEnd

Func money()
    $AmountPrize = GUICtrlRead($Input1)
    ;First Prize
    $Prize1 = $AmountPrize / 3 + 0.1
    GUICtrlSetData($Label9, $Prize1) ;this based if 100 is entered 100 / 3 + 10% = 36.7

    ;secound Prize
    $Prize2 = $AmountPrize / 3
    GUICtrlSetData($Label11, $Prize2) ;this based if 100 is entered 100 / 3 = 33.3

    ;3rd Prize
    $Prize3 = $AmountPrize / 3 - 0.1
    GUICtrlSetData($Label10, $Prize3) ;this based if 100 is entered 100 / 3 - 10% = 30
EndFunc

Func Randomnumber()
    $number = Random(1, 60,1)
    GUICtrlSetData($Label6, $number)
    $number2 = Random(1,60,1)
    GUICtrlSetData($Label7, $number2)
    $number3 = Random(1,60,1)
    GUICtrlSetData($Label8, $number3)
EndFunc
Link to comment
Share on other sites

Read the section Operators in the help file, specifically the order of operations. Division is done before addition, so:

100 / 3 + 0.1 = (100 / 3) + 0.1 = 33.43 (rounded to two places)

Add the $ES_NUMBER style to the input to accept only numeric characters.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

ok but now i have it doing 36.666666666666666666666666666 R how can i not just make it show 36.66 im sorry for asking but i have neather done maths in to a program befor.

You should be able to work something out even if you haven't done it before. The help file is there so it just means you need to know how to use it.

So look in the Contents, expand "Function Reference", expand "Math Management" and look down the list for something that might be useful. I think you'll find you can do it by yourself.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

ok i have looke throw the maths section of the help file and i sill can get the maths to work out right GGGGGGGGGGGGRRRRRRRRRRRRRRRR i hate been crap at maths and i cant get it to display the answer like this with the desimal place been 2 places 36.00

Link to comment
Share on other sites

You have got to be kidding me. This has nothing to do with you being bad at math. This is just you not wanting to search properly. There is a function called Round for crying out loud. Shame on you.

Edited by dani
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...