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

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




PostPosted: Thu Apr 23, 2009 7:51 am   Post subject: records

so doing a records assignment, this is the section i'm having problems with. i have to sort the records, but when i run it i get this error
"operands of comparison operators must be scalars, sets or strings"

so i've tried strint, intstr, still getting the error

suggestions?

Turing:


type sportsRecord :
    record
        name : string
        team : string
        position : string
        age : string
        salary : string
        rating : string
    end record


var place : array 1 .. 500 of sportsRecord

for last : 1 .. 100
    for i : 1 .. 99
        if place (i) > place (i + 1) then%<----------ERROR HERE @ THE "1" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            random := false
            const temp := place (i)
            place (i) := place (i + 1)
            place (i + 1) := temp
        end if
        %put place (i)
    end for
    exit when random
end for

Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Thu Apr 23, 2009 8:12 am   Post subject: RE:records

Your record type is a custom type. Turing has no idea how you want it to compare any particular two records. Did you want an alphabetical sort by name / team / position, a numerical sort by age, what?

You need to choose one or more of the fields to compare to get your overall sort order.

Additionally, age should probably be an integer, as should salary. Possibly rating too.
Tallguy




PostPosted: Thu Apr 23, 2009 8:26 am   Post subject: RE:records

the user is suppose to choose which to sort from, ex if i want name then alphabtializes the name then show all the data for that name then the next user and data in alphabicital order

i can't use ints they must be strings
Nick




PostPosted: Thu Apr 23, 2009 3:23 pm   Post subject: RE:records

well adding to what DemonWasp said, you can't sort by record (i) < record (i + 1) as the compiler sees record and says "wtf is that" you need to sort by record.field (i) < record.field (i+1). how to get the right field dependant on what the user inputted, I'll leave to you
DemonWasp




PostPosted: Thu Apr 23, 2009 4:04 pm   Post subject: RE:records

You need to manually select which way to sort based on user-interaction. So if the sort is 1 (by name) then you would use records(i).name > records(i+n).name or similar; if it's 2, then ... you get the picture.

Why can't you use integers for the age? I'm confused by that.
Tallguy




PostPosted: Thu Apr 23, 2009 4:46 pm   Post subject: Re: records

kk thanks everyone i finally got it working, i put the data within an array then sorted according to the array

DemonWasp wrote:


Why can't you use integers for the age? I'm confused by that.


my teacher wanted us to use strings...no idea



vanderMout_Alex_Records#2.t
 Description:

Download
 Filename:  vanderMout_Alex_Records#2.t
 Filesize:  5.7 KB
 Downloaded:  65 Time(s)

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  [ 6 Posts ]
Jump to:   


Style:  
Search: