Greatest Integer Function Problem

  • Thread starter Lobdell
  • Start date
I just need a push in the right direction for this one.
The problem is: A phone company charges this amount for the first minute and that amount for each additional minute. If someone talks for 3.1 minutes, they are charged for 4 minutes. Make a formula, blah blah blah...
Anyway I'm having trouble with making the equation work for both of these situations: when x is an integer, and when x is not an integer.
I already thought about int(x-.1) but then x could be .01, and it wouldn't be correct.

Any help is appreciated.
 

CRGreathouse

Science Advisor
Homework Helper
2,818
0
You're trying to make a "round up" function. Since you're allowed to use the floor ("round down") function, consider this:

int(x)=-int(-x), x is an integer
int(x)=1-int(-x), otherwise
 

uart

Science Advisor
2,776
9
All you need is a + b ceil(x-1), where a is the cost for the first minute and b is the cost of each additional minute.
 

Related Threads for: Greatest Integer Function Problem

  • Posted
Replies
4
Views
6K
Replies
1
Views
2K
  • Posted
Replies
5
Views
2K
  • Posted
Replies
11
Views
4K

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving

Hot Threads

Top