
-----------------------------------
Nezura
Sun May 02, 2004 4:05 pm

boolean error
-----------------------------------
This is my entire program for a school project and at the procedure 
choice5, it says my if and my elsif needs to be boolean. I'm stuck here and don't know what to do. Any help appreciated. 


% Howard Tse
% Last modified Apr.26, 2004
% Programming assignement for WOOF-WOOF-ORAMA

%procedures credited to Clement
%setscreen ("nooffscreenonly") credited to Paul Bian at compsci.ca
%explaination of mouse.where command credited to GreenTiger at compsci.ca

setscreen ("graphics:700;300")
var purchase : string
var choice : int
var back : string (1)
var mp, fp, bmp, bfp, mc, fc, sc : int
mp := 3 %male poodle
fp := 2 %female poodle
bmp := 4 %black male poodle
bfp := 5 %black female poodle
mc := 6 %male chihuahua
fc := 3 %female chihuahua
sc := 1 %sparky the talking chihuahua
var mpcounter, fpcounter, bmpcounter, bfpcounter, mccounter, fccounter, sccounter : int := 0
var cash : string
var total : real
var coupon : string
var amount : int := 0
var sum : int
function distance (x1, y1 : int) : int
    result abs (x1 - y1)
end distance

%------------------Pictures-----------------------------------------
%----------------------background including buidling------------------------
var font : int
font := Font.New ("Comic Sans MS:19")

Draw.FillBox (0, 0, 400, 300, 43) %Orange back
Draw.FillBox (400, 0, 700, 300, grey) %Building box
Draw.Box (409, 228, 687, 252, red) %box around sign
Font.Draw ("WOOF-WOOF-ORAMA", 411, 230, font, red) %store logo
font := Font.New ("Comic Sans MS:12")

Font.Draw ("By:Howard Tse", 0, 206, font, red)
Font.Draw ("Date Last modified: May 2nd, 2004", 0, 220, font, red)
Font.Draw ("Purchase a puppy from WOOF-WOOF-ORAMA", 0, 237, font, red)
Draw.Line (420, 300, 400, 285, red) %roof
Draw.Line (450, 300, 400, 260, red) %roof
Draw.Line (480, 300, 430, 260, red) %roof
Draw.Line (510, 300, 460, 260, red) %roof
Draw.Line (540, 300, 490, 260, red) %roof
Draw.Line (570, 300, 520, 260, red) %roof
Draw.Line (600, 300, 550, 260, red) %roof
Draw.Line (630, 300, 580, 260, red) %roof
Draw.Line (660, 300, 610, 260, red) %roof
Draw.Line (690, 300, 640, 260, red) %roof
Draw.Line (720, 300, 670, 260, red) %roof

Draw.Box (435, 130, 505, 200, red) %left window
Draw.Line (470, 130, 470, 200, red) %vertical line
Draw.Line (435, 165, 505, 165, red) %horizontal line
Draw.Box (595, 130, 665, 200, red) %right window
Draw.Line (630, 130, 630, 200, red) %vertical line
Draw.Line (595, 165, 665, 165, red) %horizontal line

Draw.Box (520, 0, 580, 100, red) %Door
Draw.Oval (530, 50, 5, 5, red) %door knob

var pic := Pic.New (0, 0, maxx, maxy)
cls

%----------------------------car--------------------------
Draw.FillBox (70, 100, 170, 150, brown) %car top
Draw.FillBox (170, 100, 220, 150, white) %window
Draw.Box (170, 100, 220, 150, black) %window outline
Draw.FillBox (0, 50, 290, 100, brown) %car body
Draw.FillOval (65, 30, 30, 30, red) %left wheel
Draw.FillOval (225, 30, 30, 30, red) %left wheel

var pic2 := Pic.New (0, 0, 290, 150)
cls


%--------------------------dog-------------------------
Draw.Oval (168, 158, 10, 20, black) %leg 1
Draw.Oval (190, 158, 10, 20, black) %leg 2
Draw.Oval (230, 158, 10, 20, black) %leg 3
Draw.Oval (253, 158, 10, 20, black) %leg 4
Draw.Line (268, 211, 295, 240, black) %tail
Draw.FillOval (295, 243, 10, 10, white) %tail ball
Draw.Oval (295, 243, 10, 10, black) %tail outline
Draw.FillOval (165, 143, 9, 5, black) %paw 1
Draw.FillOval (187, 143, 9, 5, black) %paw 2
Draw.FillOval (227, 143, 9, 5, black) %paw 3
Draw.FillOval (250, 143, 9, 5, black) %paw 4


Draw.FillOval (200, 200, 70, 30, white) %body
Draw.Oval (200, 200, 70, 30, black) %body outline

Draw.FillOval (142, 220, 40, 40, white) %head
Draw.Oval (142, 220, 40, 40, black) %outline of head
Draw.Line (152, 232, 159, 238, black) %right eye part 1
Draw.Line (159, 238, 165, 232, black) %right eye part 2

Draw.Line (128, 238, 135, 232, black) %left eye part 1
Draw.Line (128, 238, 122, 232, black) %left eye part 2

Draw.FillOval (100, 200, 10, 40, black) %left ear
Draw.FillOval (182, 200, 10, 40, black) %right ear
Draw.Line (130, 200, 162, 200, black) %mouth
Draw.FillArc (152, 199, 5, 10, 180, 0, black) %tongue
Draw.Oval (143, 215, 7, 7, black) %nose

var pic3 := Pic.New (89, 137, 306, 261)
cls



font := Font.New ("Comic Sans MS:19")

%-------------------Procedure code for the menu----------------------

procedure menu
    put "Please choose an option"
    put "1. Brief Description of the program"
    put "2. List of Dogs for sale"
    put "3. Purchase a dog"
    put "4. Checkout"
    put "5. Total number sold"
    put "6. View our virtual puppy"
    get choice
end menu

%-------------------Procedure code for choice 1----------------------
procedure choice1
    cls
    locate (1, 1)
    put "This program allows the user to purchase puppies from our store, "
    locate (2, 1)
    put "WOOF-WOOF-ORAMA. Once the user has chosen puppies to purchase he/she "
    locate (3, 1)
    put "will be able to see the average price, number of puppies and total "
    locate (4, 1)
    put "price with any discounts."
    locate (6, 1)
    put "Press any key to go back to the main menu"
    getch (back)
    cls
end choice1

%-------------------Procedure code for choice 2----------------------
procedure choice2
    cls
    put "    --------------------------------------------------------------------------------"
    put "    ---- PUPPY TYPE ---------------- SEX ----------- PRICE ---------- NUMBER ------"
    put "    -- 1.White Poodles                M              $199.00            ", mp, "    -------"
    put "    ---2.White Poodles                F              $199.00            ", fp, "    -------"
    put "    ---3.Black Poodles                M              $199.00            ", bmp, "    -------"
    put "    ---4.Black Poodles                F              $199.00            ", bfp, "    -------"
    put "    ---5.Yellow Chihuahuas            M              $29.99             ", mc, "    -------"
    put "    ---6.Yellow Chihuahuas            F              $29.99             ", fc, "    -------"
    put "    ---7.Sparky, Talking Chihuahua    M              $4.00              ", sc, "    -------"
    put "    --------------------------------------------------------------------------------"
    put "    Press any key to return to main menu"
    getch (back)
    cls
end choice2

%-------------------Procedure code for choice 3----------------------
procedure choice3
    cls
    loop
        cls
        put "     --------------------------------------------------------------------------------"
        put "     ---- PUPPY TYPE ---------------- SEX ----------- PRICE ---------- NUMBER ------"
        put "     -- 1.White Poodles                M              $199.00            ", mp, "    -------"
        put "     ---2.White Poodles                F              $199.00            ", fp, "    -------"
        put "     ---3.Black Poodles                M              $199.00            ", bmp, "    -------"
        put "     ---4.Black Poodles                F              $199.00            ", bfp, "    -------"
        put "     ---5.Yellow Chihuahuas            M              $29.99             ", mc, "    -------"
        put "     ---6.Yellow Chihuahuas            F              $29.99             ", fc, "    -------"
        put "     ---7.Sparky, Talking Chihuahua    M              $4.00              ", sc, "    -------"
        put "     --------------------------------------------------------------------------------"
        put "     To purchase a puppy type in the number corresponding with the type of puppy."
        put "     Type reset to choose again"
        put "     Type exit to return to main menu"
        get purchase
        if purchase = "1" then
            if mp > 0 then
                mp := mp - 1
                put "White male poodle purchased"
                delay (1000)
                mpcounter := mpcounter + 1
            else
                put "Already sold out"
                delay (1000)
            end if
        elsif purchase = "2" then
            if fp > 0 then
                fp := fp - 1
                put "White female poodle purchased"
                delay (1000)
                fpcounter := fpcounter + 1
            else
                put "Already sold out"
                delay (1000)
            end if
        elsif purchase = "3" then
            if bmp > 0 then
                bmp := bmp - 1
                put "Black male poodle purchased"
                delay (1000)
                bmpcounter := bmpcounter + 1
            else
                put "Already sold out"
                delay (1000)
            end if
        elsif purchase = "4" then
            if bfp > 0 then
                bfp := bfp - 1
                put "Black female poodle purchased"
                delay (1000)
                bfpcounter := bfpcounter + 1
            else
                put "Already sold out"
                delay (1000)
            end if
        elsif purchase = "5" then
            if mc > 0 then
                mc := mc - 1
                put "Yellow male chihuahua purchased"
                delay (1000)
                mccounter := mccounter + 1
            else
                put "Already sold out"
                delay (1000)
            end if
        elsif purchase = "6" then
            if fc > 0 then
                fc := fc - 1
                put "Yellow female chihuahua purchased"
                delay (1000)
                fccounter := fccounter + 1
            else
                put "Already sold out"
                delay (1000)
            end if
        elsif purchase = "7" then
            if sc > 0 then
                sc := sc - 1
                put "Sparky the talking chihuahua purchased"
                delay (1000)
                sccounter := sccounter + 1
            else
                put "Already sold out"
                delay (1000)
            end if
        elsif purchase = "reset" then
            mp := 3 %male poodle
            fp := 2 %female poodle
            bmp := 4 %black male poodle
            bfp := 5 %black female poodle
            mc := 6 %male chihuahua
            fc := 3 %female chihuahua
            sc := 1 %sparky
            mpcounter := 0
            fpcounter := 0
            bmpcounter := 0
            bfpcounter := 0
            mccounter := 0
            fccounter := 0
            sccounter := 0
        else
            put "Either you have entered an invalid option or the number of dogs bought is below 0"
        end if
        exit when purchase = "exit"
    end loop
    cls
end choice3

procedure choice4
    cls
    total := (mpcounter * 199) + (fpcounter * 199) + (bmpcounter * 199) + (bfpcounter * 199) + (mccounter * 29.99) + (fccounter * 29.99) + (sccounter * 4)
    put "Will you be purchasing in cash?"
    get cash
    if cash = "yes" or cash = "Yes" then
        total := total * 0.9
        put "You will be recieving a 10% discount"
    elsif cash = "no" or cash = "No" then
        put "You will not be recieving a 10% discount"
    else
        put "Invalid input"
    end if
    cls
    put "Do you have a $5.00 coupon?"
    get coupon
    if coupon = "yes" or coupon = "Yes" then
        amount := amount + 1
    elsif coupon = "no" or coupon = "No" then
        cls
    else
        put "Invalid input"
    end if
    cls
    put "These are the dogs you have purchased       Cost:"
    put "White male poodle:             ", mpcounter, "             $", mpcounter * 199
    put "White female poodle:           ", fpcounter, "             $", fpcounter * 199
    put "Black male poodle:             ", bmpcounter, "             $", bmpcounter * 199
    put "Black female poodle:           ", bfpcounter, "             $", bfpcounter * 199
    put "Yellow male chihuahua:         ", mccounter, "             $", mccounter * 29.99
    put "Yellow female chihuahua:       ", fccounter, "             $", fccounter * 29.99
    put "Sparky, the talking chihuahua: ", sccounter, "             $", sccounter * 4
    put ""
    put "Total amount of puppies        ", mpcounter + fpcounter + bmpcounter + bfpcounter + mccounter + fccounter + sccounter
    var final : real := (total * 1.15) - (amount * 5)
    if final  0 then
        sum := ((total * 1.15) - (amount * 5)) / (mpcounter + fpcounter + bmpcounter + bfpcounter + mccounter + fccounter + sccounter)
    elsif mpcounter, fpcounter, bmpcounter, bfpcounter, mccounter, fccounter, sccounter > 0 then
        sum := 0
    end if
    put "Average price of each dog sold $", sum
    put "Press any key to return to main menu"
    getch (back)
    cls
end choice5

procedure choice6
    cls
    setscreen ("offscreenonly")
    var x1, y1, x2, y2, mb : int := 320
    y1 := 200
    loop
        mousewhere (x2, y2, mb)
        if x2 > x1 then
            x1 += distance (x1, x2) div 10
        else
            x1 -= distance (x1, x2) div 10
        end if
        if y2 > y1 then
            y1 += distance (y1, y2) div 10
        else
            y1 -= distance (y1, y2) div 10
        end if

        Pic.Draw (pic3, x1, y1, picMerge)
        delay (10)
        View.Update
        cls
        exit when mb = 1
        Font.Draw ("Click to return to main menu ", 150, 50, font, red)

    end loop

end choice6



%--------------------------Openning Screen-----------------------
cls
setscreen ("offscreenonly")
for x : 1 .. 110 by 5
    Pic.Draw (pic, 0, 0, picMerge)
    Pic.Draw (pic2, x, 0, picMerge)

    View.Update
end for
put "Press any key to continue"
setscreen ("graphics:700;300")
getch (back)
cls


%--------------------------Main Screen----------------------------
setscreen ("nooffscreenonly")

loop
    setscreen ("graphics:700;300")
    setscreen ("nooffscreenonly")
    menu
    if choice = 1 then
        choice1
    elsif choice = 2 then
        choice2
    elsif choice = 3 then
        choice3
    elsif choice = 4 then
        choice4
    elsif choice = 5 then
        choice5
    elsif choice = 6 then
        choice6
    else
        put "Invalid input, please choose again"
        delay (1000)
        cls
    end if
end loop


-----------------------------------
Paul
Sun May 02, 2004 4:18 pm


-----------------------------------
ok a couple of problems, you can compare a whole lot of values using commas, u cant go
if a, b, c > 5
you can
if a> 5 and b > 5 and c>b
I dunno if theres another way.
Also the variable sum can't be integer unless u are planning to round the whole calculation.

-----------------------------------
Nezura
Sun May 02, 2004 4:29 pm


-----------------------------------
once again, i thank you paul
