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

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




PostPosted: Wed Jan 10, 2007 5:29 pm   Post subject: program problem

can you guys please take a look at my coding below? it is suppose to let the user guess 3 times, but after one input it completely stops, nothing happens. can you guys put it so that it allows the user to put in 3 different inputs then go to the proc goodBye? or when the user inputs the correct answer, it wil automatically go to proc goodBye. thanks a bunch.

here's my coding :

code:


% set screen/window size
import GUI
setscreen ("nocursor")
setscreen ("noecho")

% global declaration statement
var mainWin := Window.Open ("position:250;250, graphics:400;230")
var key : string (1)
var number, answer : int
var tries : int := 3
var playBtn, mainMenuBtn, quitBtn : int := 0

% all procedures

procedure title
    cls
    locate (1, 18)
    put "Guessing Game!"
    put ""
end title

procedure introduction
    title
    locate (4, 1)
    put "This is the newer version of the old "
    put "GUESSING GAME."
    put ""
    put "You have 3 tries to guess the correct number that"
    put "the computer has randomly chosen. Good luck! :)"
    put ""
    GUI.Show (mainMenuBtn)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)
    GUI.Refresh
end introduction

proc errorMsg
    var winID2 := Window.Open ("position:300;300, graphics:200;200")
    locate (1, 11)
    put "ERROR"
    put ""
    Window.Hide (mainWin)
    Window.Show (winID2)
    Window.SetActive (winID2)
    put "Remember that the number has to be between 50 and 100!"
    locate (7, 1)
    put "Press any key to go back and try again."
    loop
        exit when hasch
    end loop
    Window.Close (winID2)
    Window.Show (mainWin)
    Window.SetActive (mainWin)
end errorMsg

procedure randNum
    randint (answer, 50, 100)
end randNum


procedure display
    title
    locate (6, 1)
    put "Last number chosen : ", number
    locate (7, 1)
    put "This is the random number : ", answer
    delay (4000)
    cls
end display

procedure userInput
    title
    locate (4, 1)
    put "Please enter a number that is ..."
    put "between 50 and 100 : " ..
    get number
    loop
        if number < 50 or number > 100 then
            errorMsg
        elsif number > answer then
            locate (7, 1)
            put "Your guess is too high."
            put ""
            locate (7, 1)
            delay (1000)
        elsif number < answer then
            locate (7, 1)
            put "Your guess is too low."
            put ""
            locate (7, 1)
            delay (1000)
        else
            locate (7, 1)
            put "Congrats! You guessed it!"
            delay (3000)
            cls
            GUI.Show (playBtn)
            GUI.Show (quitBtn)
        end if
    end loop
end userInput

procedure goodBye
    display          %display needs go here, to display the orginial random number before exiting.
    locate (5, 8)
    put "This was created by Cassidy Nguyen."
    locate (6, 16)
    put "Thanks for playing!"
    delay (3000)
    Window.Close (mainWin)
end goodBye

proc mainMenu
    cls
    title
    locate (3, 21)
    put "MAIN MENU"
    GUI.Show (playBtn)
    GUI.Show (quitBtn)
    GUI.Hide (mainMenuBtn)
end mainMenu

% buttons
mainMenuBtn := GUI.CreateButtonFull (150, 40, 0, "Main Menu", mainMenu, 0, '^M', false)
playBtn := GUI.CreateButtonFull (130, 130, 0, "Play Game", userInput, 0, '^P', false)
quitBtn := GUI.CreateButtonFull (220, 130, 0, "Exit", GUI.Quit, 0, KEY_ESC, false)

% main program
introduction
randNum
loop
    exit when GUI.ProcessEvent
end loop

loop
    userInput
    if number not= answer then
        tries := tries - 1
        locate (9, 1)
        put " "
        locate (9, 1)
        put "Incorrect! Tries remaining: ", tries
        delay (1000)
    elsif tries = 0 then
        goodBye
    end if
end loop
userInput
goodBye


Sponsor
Sponsor
Sponsor
sponsor
ericfourfour




PostPosted: Wed Jan 10, 2007 9:13 pm   Post subject: Re: program problem

Without even running it I noticed a problem:
Turing:
loop
    if number < 50 or number > 100 then
        errorMsg
    elsif number > answer then
        locate (7, 1)
        put "Your guess is too high."
        put ""
        locate (7, 1)
        delay (1000)
    elsif number < answer then
        locate (7, 1)
        put "Your guess is too low."
        put ""
        locate (7, 1)
        delay (1000)
    else
        locate (7, 1)
        put "Congrats! You guessed it!"
        delay (3000)
        cls
        GUI.Show (playBtn)
        GUI.Show (quitBtn)
    end if
end loop

There is no exit condition here.
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: