Phone call cost.

First of all sorry if I should've posted my question in another topic.
I started C and C++ lessons a couple of weeks ago, and I have this problem to solve. Here it is below:

Mr. Tafaj has gone for a trip abroad. He wants to call his family from a call center. The rates change according to the minute you talked:

The first 3 minutes is $6
Every additional 10 seconds is $0.5

Question:
Write a program that is going to get the total seconds (seconds) talked. And then, it will print the amount due from the user.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int sec;
    float fee;

    cin>>sec;
    if(sec<=180) fee=6;
    else if(sec>180) fee=6+(?)*0.5;

    cout<<fee<<endl;
    return 0;
}


The teacher said something about using ceil function, but I dont know how am I supposed to do that. A little help here would be greatly appreciated!
The ceiling function in <cmath> would change a floating point number to the integer greater to or equal to that number, e.g. 4.5 would become 5. I'm guessing the teacher is suggesting you use that in this case because a charge of $.5 will apply even if the customer did not use the full ten seconds?

So you need to find how many seconds they went over the base 180. Then divide that by ten to get the number of units to charge at $.5. For example, if they talked for 205 seconds, there are 25 seconds over the base rate. 25.0/10 = 2.5 units. (Note you don't want that calculation to be integer division - that would make the result 2 in this example.)

Then I'm assuming that you would use the ceiling function to round that 2.5 up to 3, and charge them 3* $.50 for those additional seconds.
Yeah, that was the correct solution, thank you a lot.
Topic archived. No new replies allowed.