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
nin




PostPosted: Thu Jan 11, 2007 8:22 pm   Post subject: program problem

Everything that i want the program to do is working, but the only problem is that the display won't show when the user guess the number too high or too low. Also another problem is that it just stops when the you enter your first try.
It is suppose to make the user guess between the numbers 10 and 65, three times and in between if your guess is wrong it will tell you wether your guess is too high or too low.
Also, when you guess a number that is <10 or >65, the errortrap will show. (that is worksing properly)


* The exit button is working properly just how i want it
* The menu button and other process are working except for the problem that was mentioned above.
______________________________________________________________________________________
code:


%Set screen up
import GUI

%Declaration Section
var mainWin := Window.Open ("graphic: 640;200")
var key : string (1)
var number, randomNum : int
var try : int := 2
var mainMenuBtn, playBtn, quitBtn : int := 0

%Title
proc title
    locate (1, 34)
    put "Guessing Game"
end title

%Introduction
proc introduction
    GUI.Refresh
    title
    locate (3, 1)
    put "This program will allow you to guess a number between 10 and 65."
    GUI.Show (mainMenuBtn)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)
end introduction

%Main Menu
proc mainMenu
    cls
    GUI.Hide (mainMenuBtn)
    GUI.Show (playBtn)
    GUI.Show (quitBtn)
    title
    locate (3, 1)
    put "Select a button to proceed to the destination you desire."
    GUI.Refresh
end mainMenu

%Random Number
proc randNum
    randint (randomNum, 10, 65)
end randNum

%User input's error message
proc errorMessage
    var windID1 := Window.Open ("position:300;300,graphics: 330;100")
    locate (1, 1)
    put "Please enter a number between 10 and 65."
    locate (5, 1)
    put "To proceed, please press any key" ..
    loop
        exit when hasch
    end loop
    Window.Close (windID1)
end errorMessage

%User Input
proc userInput
    cls
    title
    locate (3, 1)
    put "Enter a number between 10 and 65: " ..
    get number
    if number < 10 or number > 65 then
        errorMessage
        userInput
    else
    end if
end userInput

%Display
proc display
    cls
    title
    randNum
    if number = randomNum then
        locate (3, 1)
        put "Good Job!"
        put "Try number: ", try

    elsif number < randomNum then
        put "Too low!"
        put "Try number:", try

    else
        put "Your guess is too high!"
    end if

    if try = 0 then
        locate (6, 1)
        put "The random number chosen was: ", randomNum
    end if
    cls
end display

%Good Bye
proc goodBye
    var windID2 := Window.Open ("graphics:640;400")
    Window.Close (mainWin)
    locate (12, 25)
    put "This program was brought to you by:"
    locate (13, 35)
    put "******** *******"
    locate (14, 39)
    put "Goodbye!"
    delay (2500)
    Window.Close (windID2)
end goodBye


%Buttons
mainMenuBtn := GUI.CreateButtonFull (260, 160, 0, "Main Menu", mainMenu, 0, '^M', false)
playBtn := GUI.CreateButtonFull (282, 220, 0, "Play Game", userInput, 0, '^P', false)
quitBtn := GUI.CreateButton (300, 130, 0, "Exit", GUI.Quit)

%Main Program
introduction
loop
    exit when GUI.ProcessEvent
end loop
goodBye

%End of program
Sponsor
Sponsor
Sponsor
sponsor
Ultrahex




PostPosted: Thu Jan 11, 2007 9:30 pm   Post subject: Re: program problem

Well those are procedures not processes for one thing just to get terminology correct.

First of all, there is nothing in order to make it so it runs three times (as in guess three times) in your code, an attempt at all would be nice so i can see where you are having trouble implementing it.

Also the same for your too high and too low, you need to check whether or not it is too high after each number or it is the number, this can be done doing if statements, it is relativity simple.

Hope this helps.
nin




PostPosted: Thu Jan 11, 2007 9:36 pm   Post subject: Re: program problem

Ultrahex @ Thu Jan 11, 2007 9:30 pm wrote:

Also the same for your too high and too low, you need to check whether or not it is too high after each number or it is the number, this can be done doing if statements, it is relativity simple.

Hope this helps.


i did the if structures already n for the code that makes the program exits wen the user have 0 tries left was already in my code but i dont noe y it isnt working?
Ldomi




PostPosted: Thu Jan 11, 2007 9:49 pm   Post subject: Re: program problem

It probably didn't work because you didnt tell the program to go to display after userinput. Try putting display in the userinput procedure (after end if) and put the display procedure before the userinput procedure so that it will run.

(And get rid if the cls's, you dont need them)

I think im in your class btw Wink
nin




PostPosted: Thu Jan 11, 2007 9:55 pm   Post subject: Re: program problem

Quote:
I think im in your class btw Wink


i am in ur class lucille =P n thanks it works =) just need to edit it a little now k! thank you soo much =P
nin




PostPosted: Thu Jan 11, 2007 9:58 pm   Post subject: Re: program problem

k this is the code now: n there is a little bit more proplem the program doesnt run again =/

code:


%Set screen up
import GUI

%Declaration Section
var mainWin := Window.Open ("graphic: 640;200")
var key : string (1)
var number, randomNum : int
var try : int := 2
var mainMenuBtn, playBtn, quitBtn : int := 0

%Title
proc title
    locate (1, 34)
    put "Guessing Game"
end title

%Introduction
proc introduction
    GUI.Refresh
    title
    locate (3, 1)
    put "This program will allow you to guess a number between 10 and 65."
    GUI.Show (mainMenuBtn)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)
end introduction

%Main Menu
proc mainMenu
    cls
    GUI.Hide (mainMenuBtn)
    GUI.Show (playBtn)
    GUI.Show (quitBtn)
    title
    locate (3, 1)
    put "Select a button to proceed to the destination you desire."
    GUI.Refresh
end mainMenu

%Random Number
proc randNum
    randint (randomNum, 10, 65)
end randNum

%User input's error message
proc errorMessage
    var windID1 := Window.Open ("position:300;300,graphics: 330;100")
    locate (1, 1)
    put "Please enter a number between 10 and 65."
    locate (5, 1)
    put "To proceed, please press any key" ..
    loop
        exit when hasch
    end loop
    Window.Close (windID1)
end errorMessage

%Display
proc display
    title
    randNum
    if number = randomNum then
        locate (3, 1)
        put "Good Job!"
        put "Try number: ", try

    elsif number < randomNum then
        put "Too low!"
        put "Try number:", try

    else
        put "Your guess is too high!"
    end if

    if try = 0 then
        locate (6, 1)
        put "The random number chosen was: ", randomNum
    end if
end display


%User Input
proc userInput
    cls
    title
    locate (3, 1)
    put "Enter a number between 10 and 65: " ..
    get number
    if number < 10 or number > 65 then
        errorMessage
        userInput
    else
    end if
    display
end userInput


%Good Bye
proc goodBye
    var windID2 := Window.Open ("graphics:640;400")
    Window.Close (mainWin)
    locate (12, 25)
    put "This program was brought to you by:"
    locate (13, 35)
    put "******** *******"
    locate (14, 39)
    put "Goodbye!"
    delay (2500)
    Window.Close (windID2)
end goodBye


%Buttons
mainMenuBtn := GUI.CreateButtonFull (260, 160, 0, "Main Menu", mainMenu, 0, '^M', false)
playBtn := GUI.CreateButtonFull (282, 220, 0, "Play Game", userInput, 0, '^P', false)
quitBtn := GUI.CreateButton (300, 130, 0, "Exit", GUI.Quit)

%Main Program
introduction
loop
    exit when GUI.ProcessEvent
end loop
goodBye

%End of program
Ldomi




PostPosted: Thu Jan 11, 2007 10:05 pm   Post subject: Re: program problem

try adding a mainMenuBtn in the display so that it will go back to the main menu and let the user play again.
nin




PostPosted: Thu Jan 11, 2007 10:10 pm   Post subject: Re: program problem

is it suppose to be like this?
code:

%Set screen up
import GUI

%Declaration Section
var mainWin := Window.Open ("graphic: 640;200")
var key : string (1)
var number, randomNum : int
var try : int := 2
var mainMenuBtn, playBtn, quitBtn : int := 0

%Title
proc title
    locate (1, 34)
    put "Guessing Game"
end title

%Introduction
proc introduction
    GUI.Refresh
    title
    locate (3, 1)
    put "This program will allow you to guess a number between 10 and 65."
    GUI.Show (mainMenuBtn)
    GUI.Hide (playBtn)
    GUI.Hide (quitBtn)
end introduction

%Main Menu
proc mainMenu
    cls
    GUI.Hide (mainMenuBtn)
    GUI.Show (playBtn)
    GUI.Show (quitBtn)
    title
    locate (3, 1)
    put "Select a button to proceed to the destination you desire."
    GUI.Refresh
end mainMenu

%Random Number
proc randNum
    randint (randomNum, 10, 65)
end randNum

%User input's error message
proc errorMessage
    var windID1 := Window.Open ("position:300;300,graphics: 330;100")
    locate (1, 1)
    put "Please enter a number between 10 and 65."
    locate (5, 1)
    put "To proceed, please press any key" ..
    loop
        exit when hasch
    end loop
    Window.Close (windID1)
end errorMessage

%Display
proc display
    GUI.Show (mainMenuBtn)
    title
    randNum
    if number = randomNum then
        locate (3, 1)
        put "Good Job!"
        put "Try number: ", try

    elsif number < randomNum then
        put "Too low!"
        put "Try number:", try

    else
        put "Your guess is too high!"
    end if

    if try = 0 then
        locate (6, 1)
        put "The random number chosen was: ", randomNum
    end if
end display


%User Input
proc userInput
    cls
    title
    locate (3, 1)
    put "Enter a number between 10 and 65: " ..
    get number
    if number < 10 or number > 65 then
        errorMessage
        userInput
    else
    end if
    display
end userInput


%Good Bye
proc goodBye
    var windID2 := Window.Open ("graphics:640;400")
    Window.Close (mainWin)
    locate (12, 25)
    put "This program was brought to you by:"
    locate (13, 35)
    put "******** ******"
    locate (14, 39)
    put "Goodbye!"
    delay (2500)
    Window.Close (windID2)
end goodBye


%Buttons
mainMenuBtn := GUI.CreateButtonFull (260, 160, 0, "Main Menu", mainMenu, 0, '^M', false)
playBtn := GUI.CreateButtonFull (282, 220, 0, "Play Game", userInput, 0, '^P', false)
quitBtn := GUI.CreateButton (300, 130, 0, "Exit", GUI.Quit)

%Main Program
introduction
loop
    exit when GUI.ProcessEvent
end loop
goodBye

%End of program
Sponsor
Sponsor
Sponsor
sponsor
Ldomi




PostPosted: Thu Jan 11, 2007 10:20 pm   Post subject: Re: program problem

yeah, something like that. Now just fix your tries (cause it always says u have 2 tries left).
Ldomi




PostPosted: Thu Jan 11, 2007 10:23 pm   Post subject: Re: program problem

Oh, and fix up your code so that you shouldn't have to use cls.
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  [ 10 Posts ]
Jump to:   


Style:  
Search: