Turbo c help!

So i have a new problem:

Daytime Calls:

1. American Region P50.00 every 3 minutes
2. Asian Region P30.00 every 2 minutes
3. African Region P40.00 every 3 minutes
4. European Region P35.00 every 2 minutes

Nightime Calls:


1. American Region P45.00 every 3 minutes
2. Asian Region P27.00 every 2 minutes
3. African Region P36.00 every 3 minutes
4. European Region P30.00 every 2 minutes

Make a program that would input destination code (between 1 to 4 ), time code (1 for day, 2 for night), the duration of the call and output the total charges

Example output :

Enter Destination Code : 2
End Time Code : 1
Duration of the Call : 39
Asian Region . . . Day time call, the charge is P585.00

Any help? thx in advance!
Last edited on
Start with:
1
2
3
4
5
6
7
8
9
10
11
12
enum regioncode
{
    America = 0, 
    Asia,
    Africa,
    Europe,
};
enum timecode
{
    day = 0,
    night,
};


Then make a class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class CALL
{
    float _length;
    signed _dest;
    signed _time;
public:
    CALL (signed dest, signed time, float duration) : _length(duration), _dest(dest), _time(time) {}
    float GetCost()
    {
        signed rate;
        switch(_time)
        {
        case day:
            switch(_dest)
            {
            case America:
                rate = .5f;
                break;
            case Asia:
                //Enter the rest here.
            case Africa:
            case Europe:
            }
            break;
        case night:
            switch(_dest)
            {
            case America:
            case Asia:
            case Africa:
            case Europe:
            }
            break;
        }
        return rate * _length;
    }
};


Finish this function, create an object with the correct constructor, and then just call GetCost()
Sorry sir, I'm just new to Turbo c, and I'm on if else statement atm. I don't understand case and call yet. Any help? thx
A case statement is part of a switch statement. It basically is saying "in case america is selected, or asia, or africa" i dont know Turbo C but i assume some things are the same as C++. Case statements are basically if statements but they are more compact and easier to work with, can you imagine nesting 100 if statements!!! that would get tricky, complicated and wouldnt work well, the switch statement solves that problem. However i dont think you can use strings in a switch statement.
Last edited on
Oh it's C! In that case classes and enums won't help (not that the class I provided was particularly wonderful).

Try something like this:

1
2
3
4
float rates[] = {50, 40, 30, 35, 45, 27, 36, 30};
int time, destination, duration;
cin >> time >> destination >> duration;
cout << duration * rates[(time-1)*4 + (destination-1)];
Last edited on
already solved =) I used else if statement. No need switch =)
Topic archived. No new replies allowed.