Computer Science Canada

coin flip program for school project

Author:  drumersrule123 [ Fri Dec 12, 2003 8:56 pm ]
Post subject:  coin flip program for school project

code:

var ht : string (1)                     % Your guess either heads or tails
var heads : string := "h"               % It sands for the heads side of the coin you type h for heads
var tails : string := "t"               % It sands for the tails side of the coin you type t for tails
var answer : int                        % The varible that chooses heads or tails
var coin : string                       % Coin is the coin and is used to distinguish heads or tails
var score: int := 0                     % The score helps keep score
var counter : int := 0                  % The counter so it will exit when it lands on heads or tails 15 times
randomize
put "Enter h for heads or t for tails"

loop



    randint (answer, 1, 2)

    if answer = 1 then
        coin := heads
    else
        coin := tails
    end if
    put " "
    put "I've flipped a coin. Is it H)eads or T)ails?" ..

    getch (ht)
    put " "
    put ""


    if ht = coin then
        score := score + 10
       
        put "Correct! Your score is ", score
        put ""
    elsif ht = "t" then
        score := score - 10
        put "Wrong! Your score is ", score
        put " "

   elsif ht = "h" then
        score := score - 10
        put "Wrong! Your score is ", score
        put " "
    else
        put "Incorrect input"
        put " "
    end if
    if ht = "h" or ht = "t" then
        counter := counter + 1
    end if
    exit when counter = 15

end loop
put " "
put "Your final score is ", score ..
put " "


dosen't have coin here is what i started for coin

code:

setscreen ("graphics:vga")
setscreen ("nocursor")
cls
const xradius := 35
var coin : int := 0
var x, y, ydir, xdir, speed : int
x := maxx div 2
y := maxy div 2
xdir := 1
ydir := - 1
speed := 15
loop
for t: 1 .. 25
    coin := coin + 1
   if coin = 35 then
   put
    coin = coin - 1
    end if
    drawfilloval (x, y, xradius, coin, yellow)
    delay (8)
    cls
end for
for c: 1 .. 25
    coin := coin - 1
   if coin = 35 then
   put
    coin = coin + 1
    end if
    drawfilloval (x, y, xradius, coin, yellow)
    delay (8)
    cls
end for
end loop

Author:  drumersrule123 [ Fri Dec 12, 2003 10:32 pm ]
Post subject: 

if any has any idea for making the coin move up and back down plz share Very Happy

Author:  McKenzie [ Fri Dec 12, 2003 11:25 pm ]
Post subject: 

drummer,

no one has responeded because they don't have a clue what you are asking. You have posted some code (include it intsead), but not made it clear,
a) what problem you are having
b) how you would like to improve your code.
The guys here are more than happy to help, but you gotta make it clear what kinda help you need.

Author:  Thuged_Out_G [ Fri Dec 12, 2003 11:32 pm ]
Post subject: 

and get ridda your pic...its huge and meeses up the whole page...ill read your code when the pic is gone, and its not a huge block of code with like 3 words per line

btw, you shouldnt be asking for help/suggestions in the submissions forum

Author:  poly [ Fri Dec 12, 2003 11:36 pm ]
Post subject: 

Quote:
if any has any idea for making the coin move up and back down plz share

well i think he wants his coin (second part of code that isnt in white) to go up and down like your really flipping a coin.

Author:  santabruzer [ Fri Dec 12, 2003 11:38 pm ]
Post subject: 

just sub for statements for the y co-ordinate.. that's simple enough

i dunnu.. you can modify this:
code:

setscreen ("offscreenonly")
setscreen ("nocursor")
cls
const xradius := 35
var coin : int := 0
var x, ydir, xdir, speed : int
x := maxx div 2
xdir := 1
ydir := -1
speed := 15

procedure coinflip (y : int)

    for t : 1 .. 25
        coin := coin + 1
        if coin = 35 then
            put
                coin = coin - 1
        end if
        drawfilloval (x, y, xradius, coin, yellow)
        delay (5)
        View.Update
        cls
    end for
    for c : 1 .. 25
        coin := coin - 1
        if coin = 35 then
            put
                coin = coin + 1
        end if
        drawfilloval (x, y, xradius, coin, yellow)
        delay (1)
        View.Update
        cls
    end for

end coinflip

loop
    for y : 1 .. 200 by 10
        coinflip (y)
    end for
    for decreasing y : 200 .. 1 by 10
        coinflip (y)
    end for
end loop

Author:  Andy [ Sat Dec 13, 2003 5:23 pm ]
Post subject: 

here is an improved version of santabruzer's code
code:
setscreen ("offscreenonly")
const xradius := 35
var xpos := maxx div 2
var height, radius := 1
var dir, side := 1

process vertical
    loop
        if height = maxy or height = 0 then
            dir := -dir
        end if
        height += 1 * dir
    end loop
end vertical

process flip
    loop
        if radius = 50 or radius = 0 then
            side := -side
        end if
        radius += side
    end loop
end flip

fork vertical
fork flip
loop
    drawfilloval (xpos, height, 50, radius, brown)
    View.Update
    cls
end loop

Author:  santabruzer [ Sat Dec 13, 2003 9:15 pm ]
Post subject: 

dodge_tomahawk wrote:
code:
        height += 1 * dir
   


Seriously.. why couldn't you make taht
code:
height += dir
... added 2 extra characters... i'm suprised..

Author:  AsianSensation [ Sat Dec 13, 2003 9:17 pm ]
Post subject: 

tsk tsk dodge, you've written some source code, but it doesnt have whatdotcolor in it......

and you call yourself the whatdotcolor warrior?

Razz

Author:  santabruzer [ Sat Dec 13, 2003 9:18 pm ]
Post subject: 

look at us.. tearing apart his code... Razz

Author:  DanShadow [ Sat Dec 13, 2003 9:33 pm ]
Post subject: 

Woah...is this post messed or is it just me? All the text is like 1 screenlength to the right. GET RID OF THAT PIC Drumersrule123! Its keeling us all.

Author:  Mazer [ Sat Dec 13, 2003 9:47 pm ]
Post subject: 

DanShadow wrote:
Woah...is this post messed or is it just me? All the text is like 1 screenlength to the right. GET RID OF THAT PIC Drumersrule123! Its keeling us all.

what are you people talking about? drummersrule's pic is fine! i've seen much larger on this site. the problem is some bug with the forum or something like that. tell dan about it

Author:  DanShadow [ Sat Dec 13, 2003 10:39 pm ]
Post subject: 

Ill pm Dan about it...
Oh and sorry, thought the pic was screwy

Author:  Mazer [ Sat Dec 13, 2003 11:08 pm ]
Post subject: 

DanShadow wrote:
thought the pic was screwy

ok, but why? am i missing something, because it looks fine to me. just a (fair sized) pic of bart simpson...

Author:  Thuged_Out_G [ Sun Dec 14, 2003 1:13 am ]
Post subject: 

i beleive when the post was made, his picture was much larger, and then after he changed his picture....there isnt any bug in the forum

Author:  DanShadow [ Tue Dec 16, 2003 12:00 pm ]
Post subject: 

Oh...well I told Dan. I thought the database couldnt be connected to because he was fixing it or something, lol.

Author:  Kuntzy [ Tue Dec 16, 2003 11:06 pm ]
Post subject: 

This is the penny i made b4 inew bout arrays lol


View.Set ("graphics:500;401,offscreenonly")
var x := 200
var y := 200
var xc := 200

var x2 : real := 180
var x3 : real := 182
var x4 : real := 184
var x5 : real := 186
var x6 : real := 188
var x7 : real := 190
var x8 : real := 192
var x9 : real := 194
var x10 : real := 196
var x11 : real := 198

var y2 : int := 200

var m := 1
var m2 : real := 1
var m3 : int := 1
var m4 : int := 1
var m5 : int := 1
var m6 : int := 1
var m7 : int := 1
var m8 : int := 1
var m9 : int := 1
var m10 : int := 1
var m11 : int := 1

var i := 0

loop


drawoval (230, 200, x, y, red)
drawline (230, 200, x + 230, y, red)
drawline (230, 200, 230 - x, y, red)
drawline (230, 200, 230, 200 + y, red)
drawline (230, 200, 230, 200 - y, red)

drawoval (230, 200, round (x2), y2, red)
drawoval (230, 200, round (x3), y2, red)
drawoval (230, 200, round (x4), y2, red)
drawoval (230, 200, round (x5), y2, red)
drawoval (230, 200, round (x6), y2, red)
drawoval (230, 200, round (x7), y2, red)
drawoval (230, 200, round (x8), y2, red)
drawoval (230, 200, round (x9), y2, red)
drawoval (230, 200, round (x10), y2, red)
drawoval (230, 200, round (x11), y2, red)


drawline (230, 200, round (x2 + 230), y2, red)
drawline (230, 200, round (230 - x2), y2, red)
drawline (230, 200, 230, 200 + y2, red)
drawline (230, 200, 230, 200 - y2, red)

drawline (230, 200, 230 + round (x * cosd (i)), 200 + round (y * sind (i)), red)
drawline (230, 200, 230 + round (x2 * cosd (i)), 200 + round (y * sind (i)), red)
drawline (230, 200, 230 - round (x * cosd (i)), 200 + round (y * sind (i)), red)
drawline (230, 200, 230 - round (x * cosd (i)), 200 - round (y * sind (i)), red)
drawline (230, 200, 230 + round (x * cosd (i)), 200 - round (y * sind (i)), red)
drawline (230, 200, 230 - round (x2 * cosd (i)), 200 + round (y * sind (i)), red)
drawline (230, 200, 230 - round (x2 * cosd (i)), 200 - round (y * sind (i)), red)
drawline (230, 200, 230 + round (x2 * cosd (i)), 200 - round (y * sind (i)), red)

drawline (230, 200, 230 + round (x * cosd (i + 90)), 200 + round (y * sind (i + 90)), red)
drawline (230, 200, 230 + round (x * cosd (i + 180)), 200 + round (y * sind (i + 180)), red)
drawline (230, 200, 230 + round (x * cosd (i + 270)), 200 + round (y * sind (i + 270)), red)
drawline (230, 200, 230 + round (x * cosd (i + 360)), 200 + round (y * sind (i + 360)), red)

drawline (230, 200, 230 + round (x2 * cosd (i + 90)), 200 + round (y * sind (i + 90)), red)
drawline (230, 200, 230 + round (x2 * cosd (i + 180)), 200 + round (y * sind (i + 180)), red)
drawline (230, 200, 230 + round (x2 * cosd (i + 270)), 200 + round (y * sind (i + 270)), red)
drawline (230, 200, 230 + round (x2 * cosd (i + 360)), 200 + round (y * sind (i + 360)), red)

drawline (230, 200, 230 - round (x * cosd (i + 90)), 200 + round (y * sind (i + 90)), red)
drawline (230, 200, 230 - round (x * cosd (i + 180)), 200 + round (y * sind (i + 180)), red)
drawline (230, 200, 230 - round (x * cosd (i + 270)), 200 + round (y * sind (i + 270)), red)
drawline (230, 200, 230 - round (x * cosd (i + 360)), 200 + round (y * sind (i + 360)), red)

drawline (230, 200, 230 - round (x2 * cosd (i + 90)), 200 + round (y * sind (i + 90)), red)
drawline (230, 200, 230 - round (x2 * cosd (i + 180)), 200 + round (y * sind (i + 180)), red)
drawline (230, 200, 230 - round (x2 * cosd (i + 270)), 200 + round (y * sind (i + 270)), red)
drawline (230, 200, 230 - round (x2 * cosd (i + 360)), 200 + round (y * sind (i + 360)), red)

x -= m
x2 -= m2
x3 -= m3
x4 -= m4
x5 -= m5
x6 -= m6
x7 -= m7
x8 -= m8
x9 -= m9
x10 -= m10
x11 -= m11

i += 1

if x < -200 then
m := -m
elsif x > 200 then
m := -m
end if
if x2 < -200 then
m2 := -m2
elsif x2 > 200 then
m2 := -m2
end if
if x3 < -200 then
m3 := -m3
elsif x3 > 200 then
m3 := -m3
end if
if x4 < -200 then
m4 := -m4
elsif x4 > 200 then
m4 := -m4
end if
if x5 < -200 then
m5 := -m5
elsif x5 > 200 then
m5 := -m5
end if
if x6 < -200 then
m6 := -m6
elsif x6 > 200 then
m6 := -m6
end if
if x7 < -200 then
m7 := -m7
elsif x7 > 200 then
m7 := -m7
end if
if x8 < -200 then
m8 := -m8
elsif x8 > 200 then
m8 := -m8
end if
if x9 < -200 then
m9 := -m9
elsif x9 > 200 then
m9 := -m9
end if
if x10 < -200 then
m10 := -m10
elsif x10 > 200 then
m10 := -m10
end if
if x11 < -200 then
m11 := -m11
elsif x11 > 200 then
m11 := -m11
end if
delay (10)
View.Update
cls
end loop

Author:  shorthair [ Wed Dec 17, 2003 11:01 pm ]
Post subject: 

Whats wrong with this page , is it the forum or is it his picture

Author:  icemaster [ Thu Jan 15, 2004 10:22 pm ]
Post subject: 

wow Kuntzy you really need to make use of the code command when you post your code, then ppl might read you code....


: