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

Username:   Password: 
 RegisterRegister   
 Can someone give me an idea on how to approach this problem?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
5pirit




PostPosted: Mon Feb 13, 2012 10:01 pm   Post subject: Can someone give me an idea on how to approach this problem?

Hey guys. Can some one give me any idea on how to approach this question?
The Prom Committee at your school will sell tickets at $65 per
person. Expenses include the cost of the food, the DJ, the
hall, the decorations, and the waiting staff. To these
expenses, add $100 for miscellaneous expenditures. Write a
program to ask for each of the expense totals incurred and
then calculate and output to the committee how many tickets
they must sell to break even.

Thanks!
Sponsor
Sponsor
Sponsor
sponsor
crossley7




PostPosted: Mon Feb 13, 2012 10:58 pm   Post subject: RE:Can someone give me an idea on how to approach this problem?

This is a relatively simple problem. You probably want to calculate total cost then find out how many tickets it takes to have an income that is equal to or greater than the expenses

If some costs are per person, then just subtract that from the cost of ticket rather than add to the total expense. Basically combine variable expenses/income and constant expenses into 2 values and solve for a single value.

ceil (expenses/cost of ticket)
Velocity




PostPosted: Tue Feb 14, 2012 4:49 pm   Post subject: RE:Can someone give me an idea on how to approach this problem?

crossley, i have a question never understood why ceil when you can just do expenses div cost of ticket to just get the whole number? isnt it more faster and efficient?
Dreadnought




PostPosted: Tue Feb 14, 2012 5:39 pm   Post subject: Re: Can someone give me an idea on how to approach this problem?

@velocity They aren't the same. Try running this:
Turing:
put "5 div 2 = ":18, 5 div 2
put "ceil (5 / 2) = ":18, ceil (5 / 2)
put "round (5 / 2) = ":18, round (5 / 2)
put "floor (5 / 2) = ":18, floor (5 / 2)
put ""
put "-5 div 2 = ":18, -5 div 2
put "ceil (-5 / 2) = ":18, ceil (-5 / 2)
put "round (-5 / 2) = ":18, round (-5 / 2)
put "floor (-5 / 2) = ":18, floor (-5 / 2)

Can you figure out what each function does? Why do you think crossley7 chose ceil over div? (remember that we are talking about paying expenses)

As for efficiency, div may (I'm not sure) actually be less efficient, but negligibly so.
crossley7




PostPosted: Tue Feb 14, 2012 11:31 pm   Post subject: RE:Can someone give me an idea on how to approach this problem?

div in this case would be the same as floor is you are doing integer division, but I am assuming real values here and also wanting it to round up.

Ceil - will round up to the nearest integer
floor - will round down to the nearest integer
round - will round up or down to the nearest integer
div - will perform integer division

You need to know the slight (though significant) differences between these functions. When dealing with integers, div and floor will give you the same result, but div cannot be used once there are real values involved
Dreadnought




PostPosted: Wed Feb 15, 2012 12:31 pm   Post subject: Re: Can someone give me an idea on how to approach this problem?

@crossley Actually, div and floor are not quite the same. Floor rounds toward negative infinity while div rounds toward zero. This means that div is equivalent to the floor of a division when the result is positive. When the result is negative, div is equivalent to the ceil of a division. Of course, ceil rounds toward positive infinity and round rounds toward the nearest integer.
RandomLetters




PostPosted: Wed Feb 15, 2012 9:53 pm   Post subject: RE:Can someone give me an idea on how to approach this problem?

More simply,

Div rounds towards 0
Ceil rounds up
Floor rounds down

Important stuff to know.
Velocity




PostPosted: Thu Feb 16, 2012 12:45 am   Post subject: RE:Can someone give me an idea on how to approach this problem?

oh okay thanks, that cleared some things up
Sponsor
Sponsor
Sponsor
sponsor
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  [ 8 Posts ]
Jump to:   


Style:  
Search: