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

Username:   Password: 
 RegisterRegister   
 Help with arrays
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
monty




PostPosted: Fri Jan 20, 2006 7:39 pm   Post subject: 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?

code:

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
Sponsor
Sponsor
Sponsor
sponsor
MiX-MaztA-M8riX




PostPosted: Fri Jan 20, 2006 8:01 pm   Post subject: (No subject)

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




PostPosted: Fri Jan 20, 2006 8:04 pm   Post subject: (No subject)

The below topic I believe would help with this. Razz

http://www.compsci.ca/v2/viewtopic.php?t=6442

oh and it's
code:
[ /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




PostPosted: Fri Jan 20, 2006 8:24 pm   Post subject: (No subject)

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




PostPosted: Sat Jan 21, 2006 11:34 am   Post subject: (No subject)

Thanks for all your help guys! Very Happy
Delos




PostPosted: Sat Jan 21, 2006 4:40 pm   Post subject: (No subject)

Talion wrote:

oh and it's
code:
[ /code] not just



That was a little confusing. Let's try it again:

code:

It's [code]...[/code]
Talion




PostPosted: Sun Jan 22, 2006 8:24 am   Post subject: (No subject)

Razz i know I made a mistake XD couldn't edit it either lol
Delos




PostPosted: Sun Jan 22, 2006 9:26 am   Post subject: (No subject)

Talion wrote:
Razz i know I made a mistake XD couldn't edit it either lol


Sure you can. Just click the little 'Edit' button.
Sponsor
Sponsor
Sponsor
sponsor
Talion




PostPosted: Sun Jan 22, 2006 9:42 am   Post subject: (No subject)

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




PostPosted: Sun Jan 22, 2006 10:09 am   Post subject: (No subject)

Delos wrote:
Talion wrote:
Razz 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




PostPosted: Sun Jan 22, 2006 11:09 am   Post subject: (No subject)

And that's what I get for leaving this place for, uh, 8 months or so.
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  [ 11 Posts ]
Jump to:   


Style:  
Search: