Computer Science Canada

Highscore List

Author:  The9thPawn [ Wed Jan 21, 2009 7:30 pm ]
Post subject:  Highscore List

I'm working on a trivia game for school, and all I have left to do is make the highscore list, I need help making it so that scores will be ranked in order from smallest to largest though, any help would be appreciated.

here is a shortened version of my program:

Turing:
loop
    var questions : array 1 .. 15 of int
    var ans1, ans2, ans3, ans4, ans5 : string
    put "Score:", score
    put ""
    put ""
    put ""
    put "" : 22, "It's time for your first question."
    delay (500)
    put ""
    put "" : 22, "This one is worth $100. Good luck."
    put ""
    var q1 := Rand.Int (1, 3)
    if q1 = 1 then
        put "" : 15, "Name the musician who after assaulting 'The Von Bondies' frontman"
        put "" : 17, "Jason Stollseimer, was forced to enroll in anger management class."
        put ""
        put "" : 19, "A)Danko Jones" : 25, "B)Phil Collins"
        put ""
        put "" : 19, "C)Gene Simmons" : 25, "D)Jack White"
        put ""
        get ans1
        cls
        if ans1 = "d" then
            put ""
            put ""
            put ""
            put ""
            put "" : 15, "Congratulations, you have answered correctly."
            put ""
            put "" : 21, "Let's move on to the next question."

        else
            put ""
            put ""
            put ""
            put ""
            put "" : 22, "I'm sorry, that answer is incorrect."
            put ""
            put "" : 24, "Come back soon to try and win "
            put "" : 10, "One Million Dollars on '---------------'!"
            exit when (ans1 = "a")
            exit when (ans1 = "b")
            exit when (ans1 = "c")
            end if
       end if
score := 100
end loop
cls
put "Please Enter your name."
get name
cls
var iStream : int
open : iStream, "Highscores.txt", put, mod, seek
seek : iStream, *
put : iStream, " "
put : iStream, name,"":15,score
close : iStream
open : iStream, "Highscores.txt", mod, seek, get, put
var text : string
loop
    exit when eof (iStream)
    get : iStream, text : *
    put text
end loop
close : iStream

______________

that's it, once again any help would be appreciated!! Smile


Mod Edit: Remember to use syntax tags! Thanks Smile
code:
[syntax="turing"]Code Here[/syntax]

Author:  DemonWasp [ Thu Jan 22, 2009 9:35 am ]
Post subject:  RE:Highscore List

You need to sort your list of high scores. There are dozens of ways of sorting, with varying efficiencies. One of the easiest to code, is called Bubble Sort (http://en.wikipedia.org/wiki/Bubble_sort); it's slower than most other sorts, but since your list is so small, slowness isn't a problem.

Author:  zero-impact [ Sat Feb 07, 2009 12:30 pm ]
Post subject:  RE:Highscore List

This should help.


: