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

Username:   Password: 
 RegisterRegister   
 How to make a program more efficent by using arrays
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
turinghelp101




PostPosted: Tue Jan 17, 2012 5:43 pm   Post subject: How to make a program more efficent by using arrays

What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
I am making a thermometer that changes temperature from fahrenheit to celcius and displays it.

What is the problem you are having?
<Answer Here>
I am not done yet, but as you can see I am individually programming each number, and one of my friends told me that the program could be made more efficent by using arrays or somthing.

1.So first of all im not sure if it can be made more efficently
2. If it can, what do you use to make it more efficent, and how can I apply it to the program
(by efficent I mean use less lines, and not having to program each individual number

Describe what you have tried to solve this problem
<Answer Here>
I really have no idea where to start Confused

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>


Turing:


<Add your code here>
This is my program:

procedure drawrectangle
    %screen formatting
    setscreen ("graphics:800;400")
    %orange button
    var number : int
    var rangeX, rangeY, button : int
    cls
    drawfillbox (200, 50, 250, 100, 42)
    %keyboard input
    put "Enter your temperature in farenheit from -4 to 68"
    get number
    put "Your temperature in celcius is:", (5 / 9) * (number - 32);
    put "Click on the orange box to repeat"


    %Mouse input
    loop
        mousewhere (rangeX, rangeY, button)
        if (rangeX >= 200 and rangeX <= 250) and (rangeY >= 50 and rangeY <= 100) and button = 1 then
            drawrectangle
        else

        end if
        %Red box
        drawbox (20, 40, 70, 100, 12)
        drawbox (20, 100, 70, 160, 12)
        drawbox (20, 160, 70, 220, 12)
        drawbox (20, 220, 70, 280, 12)
        %Yellow box
        drawbox (70, 40, 120, 100, 43)
        %Blue box
        drawbox (120, 40, 170, 100, 54)
        drawbox (120, 100, 170, 160, 54)
        drawbox (120, 160, 170, 220, 54)
        drawbox (120, 220, 170, 280, 54)
        Text.Locate (1, 5)

        for x : 50 .. 100

            % The Red Thermometer
            if number = 41 then

                drawfillbox (20, 40, 70, 0 + x, 12)
                delay (10)
            end if

            if number = 42 then
                drawfillbox (20, 40, 70, 5 + x, 12)
                delay (10)
            end if

            if number = 43 then
                drawfillbox (20, 40, 70, 10 + x, 12)
                delay (10)
            end if
            if number = 44 then
                drawfillbox (20, 40, 70, 15 + x, 12)
                delay (10)
            end if
            if number = 45 then
                drawfillbox (20, 40, 70, 20 + x, 12)
                delay (10)
            end if
            if number = 46 then
                drawfillbox (20, 40, 70, 25 + x, 12)
                delay (10)
            end if
            if number = 47 then
                drawfillbox (20, 40, 70, 30 + x, 12)
                delay (10)
            end if
            if number = 48 then
                drawfillbox (20, 40, 70, 35 + x, 12)
                delay (10)
            end if
            if number = 49 then
                drawfillbox (20, 40, 70, 40 + x, 12)
                delay (10)
            end if
            if number = 50 then
                drawfillbox (20, 40, 70, 60 + x, 12)
                delay (10)
            end if
            if number = 51 then
                drawfillbox (20, 40, 70, 65 + x, 12)
                delay (10)
            end if
            if number = 52 then
                drawfillbox (20, 40, 70, 70 + x, 12)
                delay (10)
            end if
            if number = 53 then
                drawfillbox (20, 40, 70, 75 + x, 12)
                delay (10)
            end if
            if number = 54 then
                drawfillbox (20, 40, 70, 80 + x, 12)
                delay (10)
            end if
            if number = 55 then
                drawfillbox (20, 40, 70, 85 + x, 12)
                delay (10)
            end if
            if number = 56 then
                drawfillbox (20, 40, 70, 90 + x, 12)
                delay (10)
            end if
            if number = 57 then
                drawfillbox (20, 40, 70, 95 + x, 12)
                delay (10)
            end if
            if number = 58 then
                drawfillbox (20, 40, 70, 100 + x, 12)
                delay (10)
            end if
            if number = 59 then
                drawfillbox (20, 40, 70, 115 + x, 12)
                delay (10)
            end if
            if number = 60 then
                drawfillbox (20, 40, 70, 120 + x, 12)
                delay (10)
            end if
            if number = 61 then
                drawfillbox (20, 40, 70, 125 + x, 12)
                delay (10)
            end if
            if number = 62 then
                drawfillbox (20, 40, 70, 130 + x, 12)
                delay (10)
            end if
            if number = 63 then
                drawfillbox (20, 40, 70, 135 + x, 12)
                delay (10)
            end if
            if number = 64 then
                drawfillbox (20, 40, 70, 140 + x, 12)
                delay (10)
            end if
            if number = 65 then
                drawfillbox (20, 40, 70, 145 + x, 12)
                delay (10)
            end if
            if number = 66 then
                drawfillbox (20, 40, 70, 150 + x, 12)
                delay (10)
            end if
            if number = 67 then
                drawfillbox (20, 40, 70, 160 + x, 12)
                delay (10)
            end if
            if number = 68 then
                drawfillbox (20, 40, 70, 180 + x, 12)
                delay (10)
            end if
        end for
    end loop
end drawrectangle
drawrectangle



Please specify what version of Turing you are using
<Answer Here>
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Tue Jan 17, 2012 5:57 pm   Post subject: RE:How to make a program more efficent by using arrays

There isn't anything arays will do for you here. However, for loops would help tremendously.


Read: http://compsci.ca/v3/viewtopic.php?t=3678


One you have, the majority of your code would turn into something similar to

code:

for x : 50 .. 100
     for i : 41 .. 68
         if number = i then
             drawfillbox(20, 40, 70, ((i - 41) * 5) + x, 12)
         end if
    end for
end for
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  [ 2 Posts ]
Jump to:   


Style:  
Search: