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

Username:   Password: 
 RegisterRegister   
 Simple Guessing game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DaveAngus




PostPosted: Tue Mar 18, 2008 8:25 am   Post subject: Simple Guessing game

This is a great assignment for teaching the basics of randint s



******Assignment******

Create a game that will process a random integer and then when the user guesses,
output if they are too high, too low or right on.
Also, calculate the number of guesses it takes for the user to guess the answer.



/*
Name : Dave Angus
Date : March 17th 2008
Task : Random number
*/

var num1 : int
var counter : int
var guess : int
var lvl : int
counter := 0

/*
Level selection.
Determins what the randint will be between
*/

put "Hello and welcome to the number guessing game!"
put "Please select a level to play (1-4)"
put "Level 1 = 1-25"
put "Level 2 = 1-50"
put "Level 3 = 1-75"
put "Level 4 = 1-100"
get lvl

if lvl = 1
then
randint (num1, 1, 25)
elsif lvl = 2
then
randint (num1, 1, 50)
elsif lvl = 3
then
randint (num1, 1, 75)
elsif lvl = 4
then
randint (num1, 1, 100)

end if

/* This loop is where people make the guess.
I have set a delay so that people can read if they are too high or too low.
I wanted to clear screen so that it looks cleaner*/

loop
cls
put " Please make your first guess: "
get guess


if num1 > guess then
put "You are too low. Try again!"
elsif num1 < guess then
put "You are too high. Keep going!"
elsif num1 = guess then
put "You are correct!!!"
exit
end if
counter := counter + 1
delay (2000)
end loop

/* This determines how long it took for the user to guess the number.
I have also added comments depending on their score.
*/

put "It took you " ..
put counter ..
put " guesses to correctly guess the number!"

if counter = 1 then
put "You should buy a lottery ticket!"
elsif counter <= 3 then
put "You are a robot!"
elsif counter <= 6 then
put "Good job! You should move up to a higher level."
elsif counter <= 10 then
put "Great guessing. Try to get it quicker next time!"
elsif counter >= 10 then
put "You should really get more luck!!!"

end if
Sponsor
Sponsor
Sponsor
sponsor
DaveAngus




PostPosted: Tue Mar 18, 2008 9:17 am   Post subject: RE:Simple Guessing game

anyone have any comments?
BigBear




PostPosted: Tue Mar 18, 2008 2:32 pm   Post subject: Re: Simple Guessing game

Please do not post right after you posted this is called double posting if you did not know you can edit posts and after posting multiple assignments without
DaveAngus wrote:

anyone have any comments?

You should have added it to the end. Anyways your clever ending statement doesn't take into effect your level. For example you play on hard and it takes you 6 tries it says Good job! You should move up to a higher level. However you played on the highest level. Also there should be an option to play again. Sorry about the double posting comments.
A.J




PostPosted: Tue Mar 18, 2008 3:03 pm   Post subject: Re: Simple Guessing game

Well, I have a better guessing game.

Its called MINDTRAP.
I'll be posting it (with DanielG, my partner) after adding graphics to it.

And DaveAngus......what's up with all the posts lately?
I'm pretty sure u like programming, but see if you can add graphics and make your code turing style like this:
Turing:

% code here


by adding ' syntax="Turing" ' before your code (in square brackets) and '/syntax' after it (also in square brackets).
Zampano




PostPosted: Tue Mar 18, 2008 3:12 pm   Post subject: Re: Simple Guessing game

I dislike the "syntax=" tags. Sometimes they distort the meaning of the code through errors in colouring. A better alternative exists in "code" tags.
CodeMonkey2000




PostPosted: Tue Mar 18, 2008 3:19 pm   Post subject: RE:Simple Guessing game

You don't really need graphics, but you really should be using Rand.Int(x,y). randint modifies your variables from out side the program, whereas Rand.Int returns a random value between x and y.
fishtastic




PostPosted: Tue Mar 18, 2008 4:50 pm   Post subject: RE:Simple Guessing game

code:
if lvl = 1
then
randint (num1, 1, 25)
elsif lvl = 2
then
randint (num1, 1, 50)
elsif lvl = 3
then
randint (num1, 1, 75)
elsif lvl = 4
then
randint (num1, 1, 100)


can be shorten into
code:

num1:=Rand.Int(1,lvl*25)


this made me feel better while doing biology homework Smile gj !
DaveAngus




PostPosted: Wed Mar 19, 2008 8:11 am   Post subject: Re: Simple Guessing game

BigBear @ Tue Mar 18, 2008 2:32 pm wrote:
Please do not post right after you posted this is called double posting if you did not know you can edit posts and after posting multiple assignments without
DaveAngus wrote:

anyone have any comments?

You should have added it to the end. Anyways your clever ending statement doesn't take into effect your level. For example you play on hard and it takes you 6 tries it says Good job! You should move up to a higher level. However you played on the highest level. Also there should be an option to play again. Sorry about the double posting comments.



Hey BigBear.
Thanks again for the comment.
I am actually VERY new to programming.
The assignments that I have been posting are ones I am doing in class.
If you could like me know how to make that comment depend on the level,
that would be great.

This is literally my first week programming.
So all of the help would be great!



Also, with the doubble posts,
I am also new to this site so I didnt know that.
Thanks a lot for letting me know!
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: