Author |
Message |
Tallguy
![](http://compsci.ca/v3/uploads/user_avatars/515706924539b443d32a6e.gif)
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: 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.
|
|
|
|
|
![](images/spacer.gif) |
Tallguy
![](http://compsci.ca/v3/uploads/user_avatars/515706924539b443d32a6e.gif)
|
Posted: 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
|
|
|
|
|
![](images/spacer.gif) |
Nick
![](http://compsci.ca/v3/uploads/user_avatars/19644337547e837b41d67a.png)
|
Posted: 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
|
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: 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.
|
|
|
|
|
![](images/spacer.gif) |
Tallguy
![](http://compsci.ca/v3/uploads/user_avatars/515706924539b443d32a6e.gif)
|
Posted: 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
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
vanderMout_Alex_Records#2.t |
Filesize: |
5.7 KB |
Downloaded: |
65 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
|