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

Username:   Password: 
 RegisterRegister   
 Help with my program.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hasassin




PostPosted: Mon May 18, 2009 1:06 pm   Post subject: Help with my program.

What is it you are trying to achieve?
This turing program is an assignment from my computer science class in high school. The objective is to open a file, read it, and then program it to scroll through it.

What is the problem you are having?
I am trying to set limitations to my scroll, however, when I attempt to do that by putting IF statements, the program chokes, and says that "VARIABLE HAS NO VALUE."

Describe what you have tried to solve this problem
I asked a classmate for help, however, he could not help me, he didn't know how to resolve it.


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

Turing:


%Declare the arrays
var job : array 1 .. 70 of string
var males : array 1 .. 70 of int
var females : array 1 .. 70 of int
var averageincome : array 1 .. 70 of int
var femaleper : array 1 .. 70 of real

%declare the variables
var fileID : int
var count : int := 1
var ch : string (1)
var upBound : int := 1
var lowBound : int := 23



%declare procedure
procedure MainFile

    var stream, fileID : int
    put "Loading..."
    delay (500)
    open : fileID, "jobs.txt", get
    loop
        exit when eof (fileID)
        get : fileID, job (count) : *
        get : fileID, males (count)
        get : fileID, females (count)
        get : fileID, averageincome (count)
        femaleper (count) := females (count) / (males (count) + females (count)) * 100
        count := count + 1
    end loop
    close : fileID
end MainFile



procedure displayLines (start, finish : int)
    locate (1, 1)
    put "Occupation" : 35, "Males " : 10, " Females " : 10, " Avg Income " : 10, "% Fem" : 10
    for i : start .. finish
        put job (i) : 35, males (i) : 10, females (i) : 10, averageincome (i) : 10, femaleper (i) : 10 : 2
    end for
end displayLines



% MAIN PROGRAM
MainFile
displayLines (upBound, lowBound)

loop
    if hasch then
        getch (ch)
        if ch = KEY_DOWN_ARROW then
            upBound += 1
            lowBound := upBound + 23
            displayLines (upBound, lowBound)
            if upBound + 23 = 43 then
                upBound := 43
                lowBound := 66
                displayLines (upBound, lowBound)
            end if
        end if
    end if
end loop






Please specify what version of Turing you are using
4.1.1 Turing.
Sponsor
Sponsor
Sponsor
sponsor
zero-impact




PostPosted: Mon May 18, 2009 1:20 pm   Post subject: RE:Help with my program.

We need the input file to be able to help.
Hasassin




PostPosted: Mon May 18, 2009 3:50 pm   Post subject: Re: Help with my program.

Alright, here is the input file.


jobs.txt
 Description:

Download
 Filename:  jobs.txt
 Filesize:  2.68 KB
 Downloaded:  87 Time(s)

Hasassin




PostPosted: Mon May 18, 2009 11:20 pm   Post subject: Re: Help with my program.

Sorry for the double post, but i really want to know whats wrong here.

Thanks.
Dusk Eagle




PostPosted: Tue May 19, 2009 12:06 am   Post subject: Re: Help with my program.

I've found your problem, but it's better if you're able to solve it yourself. One good way to debug small programs like this is to add debugging output that shows important variables to the debugger each time through a loop. So, at any line you're having problems with, try making a few "put [variable]" and see what's going wrong.

If you try this and can't figure it out, then come back.
DanTheMan




PostPosted: Tue May 19, 2009 8:34 am   Post subject: RE:Help with my program.

What line in your code is getting the error (Or being highlighted) and I might be able to help you. Dusk Eagle, even though I hate to object you, you aren't a frickin teacher :/
Dusk Eagle




PostPosted: Tue May 19, 2009 1:44 pm   Post subject: Re: Help with my program.

True, I am not a teacher, but I still think it's best that people try to solve problems for themselves. That's why I suggested a way for him to figure out the problem he is having on his own. It isn't a particularly difficult problem, and he hasn't responded back saying that he's tried my way and couldn't figure it out, so why should I give him any further help? Now Hasassin, if you can't figure the problem out after trying the way I suggested, I would be more than happy to give a more direct answer.
Hasassin




PostPosted: Tue May 19, 2009 2:39 pm   Post subject: Re: Help with my program.

Erm. I tried putting some variables in the line i had trouble with, which was:

put job (i) : 35, males (i) : 10, females (i) : 10, averageincome (i) : 10, femaleper (i) : 10 : 2

I'm still clueless on how to solve the "variable has no value".
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Tue May 19, 2009 5:46 pm   Post subject: RE:Help with my program.

When you get a "variable has no value" (or the similar error message "variable not initialized"), that means that you haven't given that variable any value. Its value is whatever was sitting in memory at that location when you created the variable, which generally leads to hard-to-find issues, so Turing warns you about the problem.

Just assign the variable a value.
Hasassin




PostPosted: Tue May 19, 2009 6:20 pm   Post subject: Re: Help with my program.

I can't, or can i? I'm using an array, not a simple variable, plus, the program runs however when i scroll down all the way to the end of the file, then the error shows, just to say it again.
DemonWasp




PostPosted: Tue May 19, 2009 6:51 pm   Post subject: RE:Help with my program.

You can assign a value - to each element in the array. It is possible for some elements in an array have values while others do not; trying to read the unassigned values results in an error, while reading the values that have been assigned works just fine.

Your code that displays the values is a little off. Consider what happens when you have (for example), 30 records. Then your upperBound variable starts at 1. I hit down-arrow seven times, so upperBound is 8 and lowerBound is 31. Your program then tries to display records 8, 9, 10, ..., 30, 31.

Whoops.

You don't have a record 31. That's unfortunate. Maybe you should consider limiting it so that when you hit down-arrow and are at the bottom of the file (that is, your lowerBound is equal to the number of records), it doesn't do anything.
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  [ 11 Posts ]
Jump to:   


Style:  
Search: