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

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




PostPosted: Tue Apr 03, 2012 10:27 am   Post subject: Counting loops

What is it you are trying to achieve?
Trying to get my pricing program to count the # of tickets (how many loops), and what the total price will be
What is the problem you are having?
I can get the loop working but when i finish the loop i cant get it to count

Describe what you have tried to solve this problem
I've tried using forloops and failed

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


var age : int

loop
    put "Enter the age of the person needing a ticket, or enter 999 to finish."
    get age
    if age >= 0 and age <= 12 then
        put "your ticket is free and untaxed"
        put ""
    elsif age >= 13 and age <= 17 then
        put "your ticket price is $5, HST is 13%, your total is $", 5 * 1.13
        put ""
    elsif age >= 18 and age <= 59 then
        put "your ticket price is $10, HST is 13%, your total is $", 10 * 1.13
        put ""
    elsif age >= 60 and age not= 999 then
        put "your ticket price is $7, HST is 13%, your total is $", 7 * 1.13
        put ""
    elsif age = 999 then
        put ""
        exit when age = 999
    else
        put "you aren't yet born"
        put ""
    end if
end loop

Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Tue Apr 03, 2012 1:03 pm   Post subject: Re: Counting loops

Use a variable to keep track of things like the number of tickets sold. Set it to zero at the start, then just add to it as you receive input.
HB




PostPosted: Wed Apr 04, 2012 9:43 am   Post subject: Re: Counting loops

var tickets:int
var total:real

what now?
Dreadnought




PostPosted: Wed Apr 04, 2012 11:24 am   Post subject: Re: Counting loops

Every time you sell a ticket add 1 to the number of tickets sold, and add the price to the total cost. (Make sure you start the variables at zero)
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  [ 4 Posts ]
Jump to:   


Style:  
Search: