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

Username:   Password: 
 RegisterRegister   
 how to make a counter?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
battleroyale




PostPosted: Fri Apr 15, 2005 4:55 pm   Post subject: how to make a counter?

OK......how do you make a counter for a lottery game or w/e. Like you have money and if you win you get w/e. and if you lose you lose w/e.
plz help
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Fri Apr 15, 2005 5:29 pm   Post subject: (No subject)

A 'counter' is a fancy name for a variable.

code:

var iAmNotACounter : int := 0
% Note the initialization before anything else is done.

for i : 1..5
put i
iAmNotACounter += 1
end for

put iAmNotACounter


Oh, in case you're wondering, 'iAmNotACounter' is a counter.
battleroyale




PostPosted: Fri Apr 15, 2005 5:48 pm   Post subject: (No subject)

ok...how would i use that too make a score chart...like you start off with a number..and if you win..the number goes up..but if you lose the number goes down...can you use if statements?
[Gandalf]




PostPosted: Fri Apr 15, 2005 5:59 pm   Post subject: (No subject)

Of course (and I showed the same thing as above on your previous post Neutral).
code:

if result := win then
score += 1
elsif result := loss then
score -= 1
end if
battleroyale




PostPosted: Fri Apr 15, 2005 6:27 pm   Post subject: (No subject)

sorry gandalf for using up your time...ill stick with this thread now..
ok...for your code
code:

if result := win then
score += 1
elsif result := loss then
score -= 1
end if


how would i start it...cuz i dont know how to declare result (cuz im a noob Very Happy ) here is the code i have written so far

code:

var number : int
var number2 : int
var number3 : int


var numpick : int
var numpick2 : int
var numpick3 : int

proc theend
    cls
    put "Thank you for playing Woodbridge lotto"
    delay (2000)
    put "Kevin Nguyen"
    delay (2000)
    quit
end theend
proc Q2
    randint (number, 1, 50)
    randint (number2, 1, 50)
    randint (number3, 1, 50)
 
    put "Your numbers are "
    delay (750)
    locate (5, 25)
    put numpick
    delay (750)
    locate (5, 30)
    put numpick2
    delay (750)
    locate (5, 35)
    put numpick3
   

    put skip
    put "The lottery numbers are "
    delay (750)
    locate (15, 25)
    put number
    delay (750)
    locate (15, 30)
    put number2
    delay (750)
    locate (15, 35)
    put number3

    if numpick = number or numpick = number2 or numpick = number3
            or numpick2 = number or numpick2 = number2 or numpick2 = number3
            or numpick3 = number or numpick3 = number2 or numpick3 = number3 then
        put skip
        put "Goodjob, you won!"
        put skip
            var yorn1 : string
            put "Want to try again? y or n"
            get yorn1
            if yorn1 = "n" then
            theend
            end if

        else
            put "try again"
            put skip
            var yorn : string
            put "Want to try again? y or n"
            get yorn
            if yorn = "n" then
                theend
            else
end if


            end if

   
end Q2

loop

cls
    put "Pick 3 numbers between 1 and 50."

    get numpick, numpick2, numpick3
   
    var yorn : string
    put "Are you sure? y or n"
    get yorn : *
    cls
    if yorn = "y" then
        Q2
    end if
end loop







I want to add somewhere the money you start off with ($5) and if you win..you add 10 bucks and if you lose you lose a buck (or w/e) the stuff that iv tried kept resetting the start money to 5....help

ps. as you can see...i dont understand arrays so its really long and repetitive...
[Gandalf]




PostPosted: Fri Apr 15, 2005 7:06 pm   Post subject: (No subject)

To declare you use something like this
result := "win"
after already identifying result as a string.

So, for an example:
code:

var result : string
var score : int := 10
if this := that then
put "you won"
score += 10 %adds 10 to the current score
result := win  %says that the result is now "win"
elsif this := notthat then
put "you lost"
score -= 10
result := lost
end if
put score

Try adapting that to your program.

Also, to make your program more efficient and neat when declaring many similar variables use this:
code:

var num1, num2, num3 : int

Or later on, to improve this idea further research arrays, you might want to check one of the tutorials for that.

Hope this helps!
battleroyale




PostPosted: Sat Apr 16, 2005 12:36 pm   Post subject: (No subject)

thanks..it did...all i need to do is clean it up and add some colour... THANKS again
shlitiouse




PostPosted: Mon Apr 18, 2005 8:22 am   Post subject: (No subject)

Hi, I noticed that you had asked about giving the user a set amount of money that they could use, I read through the advice and didn't see anyone mention anything about it. It would just be a simple question of adding

code:

var money:int:=5

if result=win then
   money +=1
else
   if result=loss then
      money -=1
   end if
end if


This is basicaly what you were doing before, except you're giving the variable a set number. If you want to make the game a little more interesting, you could make different difficulty levels that would let the user start out with more or less money, depending on the difficulty selected. This can be done with a "difficulty" variable, a couple more IF statements, and a get statement at the beggining. I'll let you have fun trying out these suggestions, rather than posting how to do it. But if you get stuck feel free to ask[/code]
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Mon Apr 18, 2005 9:57 pm   Post subject: (No subject)

Ya, if you looked more closely you would see I did have that.
Quote:
var score : int := 10

score += 10 %etc, etc...


Anyways, if you did want to have a difficulty setting, or just allow the user to input the amount of starting money then (according to my code):

code:
get input
score := input


and then just work with that, its pretty simple once you understand it...

Now I suggest you look up arrays - the earlier you learn them the less trouble you're going to have (trust me Surprised).
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  [ 9 Posts ]
Jump to:   


Style:  
Search: