Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Calculator
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Evilkilla




PostPosted: Wed Jun 02, 2004 1:21 pm   Post subject: Calculator

cannot use more than one operator, tan does not work, and decimal , backspace
code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Pic.ScreenLoad ("calc.jpg", 0, 0, picCopy) %loads calulator image
var a, d : string := ""
var b, c, total : real
var switch : boolean := false
var operator : int
var x, y, button : int
var font1 : int := Font.New ("serif:12")


Mouse.ButtonChoose ("multibutton")
var button2, left, middle, right : int
var output : string
Mouse.Where (x, y, button)
left := button mod 10                   % left = 0 or 1
middle := (button - left) mod 100           % middle = 0 or 10
right := button - middle - left             % right = 0 or 100h

loop
    Mouse.Where (x, y, button)
    Text.Locate (1, 1)
    if button = 0 then
        put x : 4, "  ", y : 4, "  button up"
    else
        put x : 4, "  ", y : 4, "  button down"
    end if

    %%%%%%%%%%%%%%%
    %Button choose%
    %%%%%%%%%%%%%%%



    locatexy (27, 190)
    %button x squared
    if x >= 11 and x <= 43 and y >= 83 and y <= 113 and button = 1 then
        a := a + "**2"
        switch := true
        operator := 4

        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "0"
    elsif x >= 51 and x <= 82 and y >= 83 and y <= 113 and button = 1 then
        a := a + "0"
        if switch = false then
            b := strint (a)
        else
            d := d + "0"
            c := strint (d)
        end if
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "1"
    elsif x >= 89 and x <= 122 and y >= 83 and y <= 113 and button = 1
            then

        a := a + "1"
        if switch = false then
            b := strint (a)
        else
            d := d + "1"
            c := strint (d)
        end if
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "2"
    elsif x >= 127 and x <= 160 and y >= 83 and y <= 113 and button = 1
            then
        a := a + "2"

        if switch = false then
            b := strint (a)
        else
            d := d + "2"
            c := strint (d)
        end if
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "3"
    elsif x >= 165 and x <= 198 and y >= 83 and y <= 113 and button = 1 then
        a := a + "3"
        if switch = false then
            b := strint (a)
        else
            d := d + "3"
            c := strint (d)
        end if
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "4"
    elsif x >= 204 and x <= 236 and y >= 83 and y <= 113 and button = 1 then
        a := a + "4"
        if switch = false then
            b := strint (a)
        else
            d := d + "4"
            c := strint (d)
        end if
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button +
    elsif x >= 241 and x <= 273 and y >= 83 and y <= 113 and button = 1 then
        a := a + "+"
        switch := true
        operator := 1
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button -
    elsif x >= 279 and x <= 313 and y >= 83 and y <= 113 and button = 1
            then
        a := a + "-"
        switch := true
        operator := 2
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button backspace
    elsif x >= 316 and x <= 364 and y >= 83 and y <= 113 and button = 1 then
c:= 0
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button square root
    elsif x >= 8 and x <= 42 and y >= 47 and y <= 75 and button = 1 then
        a := a + "sqrt"
        switch := true
        operator := 5
        loop

            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "5"
    elsif x >= 50 and x <= 84 and y >= 47 and y <= 75 and button = 1 then
        a := a + "5"
        if switch = false then
            b := strint (a)
        else
            d := d + "5"
            c := strint (d)
        end if
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "6"
    elsif x >= 91 and x <= 121 and y >= 47 and y <= 75 and button = 1 then
        a := a + "6"
        if switch = false then
            b := strint (a)
        else
            d := d + "6"
            c := strint (d)
        end if
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "7"
    elsif x >= 128 and x <= 161 and y >= 47 and y <= 75 and button = 1 then
        a := a + "7"

        if switch = false then
            b := strint (a)
        else
            d := d + "7"
            c := strint (d)
        end if
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "8"
    elsif x >= 164 and x <= 191 and y >= 47 and y <= 75 and button = 1 then
        a := a + "8"
        if switch = false then
            b := strint (a)
        else
            d := d + "8"
            c := strint (d)
        end if

        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "9"
    elsif x >= 202 and x <= 236 and y >= 47 and y <= 75 and button = 1 then
        a := a + "9"

        if switch = false then
            b := strint (a)
        else
            d := d + "9"
            c := strint (d)
        end if
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "x-multiply"
    elsif x >= 241 and x <= 273 and y >= 47 and y <= 75 and button = 1 then
        a := a + "x"
        switch := true
        operator := 3
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "/"
    elsif x >= 279 and x <= 312 and y >= 47 and y <= 75 and button = 1 then
        a := a + "/"
        switch:=true
        operator:=6
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button Delete
    elsif x >= 316 and x <= 363 and y >= 47 and y <= 75 and button = 1 then
                a := ""
        cls
        Pic.ScreenLoad ("calc.jpg", 0, 0, picCopy)
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button Tan
    elsif x >= 65 and x <= 111 and y >= 9 and y <= 41 and button = 1 then
        a := a + "Tan"
        switch:=true
        operator:=8
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button COS
    elsif x >= 115 and x <= 162 and y >= 9 and y <= 41 and button = 1 then
        a := a + "Cos"
        switch:=true
        operator:=9
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button"."
    elsif x >= 162 and x <= 200 and y >= 9 and y <= 41 and button = 1 then
        a := a + "."
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "pie"
    elsif x >= 205 and x <= 237 and y >= 9 and y <= 41 and button = 1 then
        a := a + "pie"
        switch:=true
        operator:=7
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button "("
    elsif x >= 242 and x <= 275 and y >= 9 and y <= 41 and button = 1 then
        a := a + "("
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button ")"
    elsif x >= 280 and x <= 313 and y >= 9 and y <= 41 and button = 1 then
        a := a + ")"
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
        %Button Enter
    elsif x >= 317 and x <= 364 and y >= 9 and y <= 41 and button = 1 then

        locatexy (24, 140)
        %Addition
        if operator = 1 then
           total := b + c
            put total..
            %Substraction
        elsif operator = 2 then
            total := b - c
            put total..
            %Multiplication
        elsif operator = 3 then
            total := b * c
            put total..
            %X Squared
        elsif operator = 4 then
            total := b**2
            put total..
            %Square root
        elsif operator = 5 then
            total := sqrt (b)
            put total..
            elsif operator=6 then
            total:=b div c
            put total
            elsif operator=7 then
            total:=3.1415926535897932384626433832795*b
            put total
            elsif operator=8  then %NOT DONE TAN
           total:=b*0.02
           put total..
           
            %Cos
            elsif operator =9 then
            total:=cos (b)
            put total
       
       
            locatexy (27, 190)

       put " "
       
           
        end if
        loop
            mousewhere (x, y, button)
            exit when button not= 1
        end loop
    end if



    %Output Value
    locatexy (27, 190)

    put a..
end loop





[/img]



calc.jpg
 Description:
 Filesize:  102.83 KB
 Viewed:  1283 Time(s)

calc.jpg


Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Wed Jun 02, 2004 7:38 pm   Post subject: (No subject)

1) Attatch a .t file for that much code.
2) Even better, attatch a .zip file seeing as you have .ts and .jpgs there.
3) Why not just use GUI? Not quite as attractive, but at least you don't have to worry about button position detection.
4) Even better suggestion: only post problematic code, you'll get far more useful help.
Evilkilla




PostPosted: Wed Jun 02, 2004 8:20 pm   Post subject: (No subject)

not mine, my friends he needed help i didn't know how to help him.. so i helped him post, mine is gui based
SuperGenius




PostPosted: Wed Jun 02, 2004 8:26 pm   Post subject: (No subject)

i believe holtsoft added the tan function in v 4.05
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: