
-----------------------------------
monty
Fri Jan 20, 2006 7:39 pm

Help with arrays
-----------------------------------
I am making a program for school and I want to make this program so that when you type in a letter it gives you an error message and starts again. Right now the program just exits when you type in a letter. What should I do?


var foodcost : array 1 .. 10 of string :=
    init ("$3.00", "$1.00", "$2.00", "$1.25", "$1.00", "$0.50", "$4.00", "$3.75", "$2.50", "$2.00")

var foodname : array 1 .. 10 of string :=
    init ("1. Hamburger", "2. Pop", "3. French Fries", "4. Chips", "5. Chocolate", "6. Cookie", 
    "7. Pizza", "8. Sub", "9. Poutine", "10. Brownie")

var a : array 1 .. 10 of real :=
    init (3.00, 1.00, 2.00, 1.25, 1.00, 0.50, 4.00, 3.75, 2.50, 1.00)    
    
var food : string
var cost, tax, total, given, give : real
var answer2 : string

cost := 0
tax := 0

var answer : int
var answer3 : string

loop
loop

put "":15, "Food":25, "Cost"
put "":15, "----":25, "----"
put ""
for x : 1 .. 10
    put "": 10, foodname (x) : 30, foodcost (x)
end for 
    locate (20,1)
    put "Please enter the number of the food item:"
    locate (20, 42)
    get answer 
    if answer < 0 then
        put "That is not an available choice please enter the number again."        
        delay (500)
    elsif answer > 10 then
        put "That is not an available choice please enter the number again."        
        delay (500)
    elsif answer < 10 then
        if answer = 1 or answer = 3 or answer > 6 then
            cost :=  cost + a (answer)
        elsif
        answer = 2 or answer = 4 or answer = 5 then
             cost :=  cost + a (answer)
            tax := tax + a (answer) * 0.15
        end if
        locate (22,1)
        put "Is that everything? (yes/no)"
        locate (22,30)
        get answer3
        exit when answer3 = "yes"
        end if
    cls
end loop

total := cost + tax

cls
put "The total cost before taxes is: $", cost :2:2
put "The taxes are:                  $", cost :2:2
put "The final total is:             $", total:2:2
delay (2000)
cls

loop
    locate (1,1)
    put "How much money was given?"
    locate (1, 27)
    get given
    give := given - tax - cost
if give >= 0 then
    locate (3,1)
    put "Please give the customer : $", give:2:2
    delay (3000)
    cls
else
    put "That is not enough money."
    delay (500)
    cls
end if
exit when give >= 0
end loop

put "Would you like to make another purchase?"
get answer2
exit when answer2 = "no"
cls
end loop


-----------------------------------
MiX-MaztA-M8riX
Fri Jan 20, 2006 8:01 pm


-----------------------------------
Ok, you say you want the program to make an error message than quit.. and isn't that what its doing? Or did you not type what you meant? I'm confuzzled!@

-----------------------------------
Talion
Fri Jan 20, 2006 8:04 pm


-----------------------------------
The below topic I believe would help with this. :P 

http://www.compsci.ca/v2/viewtopic.php?t=6442

oh and it's  [ /code] not just 

he means he wants it to say someting like its an invalid thing entered then loop back for you to enter it again i believe

-----------------------------------
Rasta Fella
Fri Jan 20, 2006 8:24 pm


-----------------------------------
For more infromation on Arrays, Fleible Array etc. check the Turing Wallthrough or more specificly check this link below:

Arrays:
http://www.compsci.ca/v2/viewtopic.php?t=366

-----------------------------------
monty
Sat Jan 21, 2006 11:34 am


-----------------------------------
Thanks for all your help guys! :D

-----------------------------------
Delos
Sat Jan 21, 2006 4:40 pm


-----------------------------------

oh and it's  [ /code] not just 


That was a little confusing.  Let's try it again:


It's [code]...[/code]


-----------------------------------
Talion
Sun Jan 22, 2006 8:24 am


-----------------------------------
:P i know I made a mistake XD couldn't edit it either lol

-----------------------------------
Delos
Sun Jan 22, 2006 9:26 am


-----------------------------------
:P i know I made a mistake XD couldn't edit it either lol

Sure you can.  Just click the little 'Edit' button.

-----------------------------------
Talion
Sun Jan 22, 2006 9:42 am


-----------------------------------
Like I don't see one.  Not on any of the posts i've done at all.  You sure that isn't a mod thing? Hm, I'll see if I can edit this post...prolly not.

-----------------------------------
Cervantes
Sun Jan 22, 2006 10:09 am


-----------------------------------
:P i know I made a mistake XD couldn't edit it either lol

Sure you can.  Just click the little 'Edit' button.

Editing posts in the Help forum has been removed temporarily.  A while ago some people were posting questions, then editing out their question when they got the help they needed.

-----------------------------------
Delos
Sun Jan 22, 2006 11:09 am


-----------------------------------
And that's what I get for leaving this place for, uh, 8 months or so.
