Hello. I have this tutorial and I'm at a lost. The program is suppose to calculate the call charges according to the rates. conditions:

a) all calls start at 600pm and before 700am will be given 50% discount from the normal rate
b) any calls that starts at 700am and before 600pm will be charged the normal rate
c) the normal charge is 0.30 per minute

so far i got the conditions right but lets say if call time starts at 1745 and duration is 30 minutes which means call ends at 1815, there's that 15 minuts of normal rate and 15 minute of 50% discount which total charge would be 6.75. That's the part I'm stuck on.

code:

/*
ALGORITHM
READ INPUT VALUE CALL TIME
READ INPUT VALUE DURATION
CALCULATE CALL CHARGE
DISPLAY CALL CHARGE
*/

#include<stdio.h>

typedef struct {
    int time; 
    int duration;
    float charge;
}telephonecharge;

void calculateCharge(int, telephonecharge [20]);

int main() {
    int i, numCalls, First, Last;
    telephonecharge input[20];

    printf("Insert number of calls : \r\n");
    scanf_s("%d", &numCalls);

    for (i = 0; i < numCalls; i++) {
        printf("\r\nInsert Call Time and Call Duration : \r\n");
        scanf_s("%d %d", &input[i].time, &input[i].duration);   
    }

    calculateCharge(numCalls, input);

    for (i = 0; i < numCalls; i++) {
        printf("Call Time : %d,  Duration : %d, Charge : RM %.2f \r\n", input[i].time, input[i].duration, input[i].charge);
    }

    return 0;
}

void calculateCharge(int N, telephonecharge data[20]) { //N = numCalls
    int i;
    float c;

    for (i = 0; i < N; i++) {
        if (data[i].time > 1759 || data[i].time < 700) {
            c = data[i].duration * 0.15;
            data[i].charge = c;
        }

        if (data[i].time > 659 || data[i].time < 1800) {
            c = data[i].duration * 0.30;
            data[i].charge = c;
        }
    }
}

everytime i think i've got it, i actually don't got it. like i thought of separating the hours and minutes by division and modulus and comparing the minutes by 60 and have some calculation there but then i got confused again by the calculation part. I'm hoping someone can help me out. thanks!

I'd suggest to loop through duration minutes and calculate the cost minute by minute, I've got excited an tried it myself.. it works just fine.

I read the conditions. Nowhere do they say that the rate changes during the call. They say the whole call is billed at a rate that depends only on when the call started.
You seem to have made an assumption that's not justified by the information you provided.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.