Hi i am a total beginner and studying for a FD degree in C++.
My assignment states
Assignment Details

a telephone company requires a program to calculate call charges for their customers. The regular charge rate for long distance phone calls is £1.50 for the first 3 minutes (or part thereof), and 30p for each subsequent minute.

However, rates are reduced during certain hours, as indicated below:

Starting Time   Monday to Friday        Saturday and Sunday
Before 8am  40% discount                60% discount
8am to 4:59pm   Regular charge rate     60% discount
5pm to 10:59pm  30% discount            60% discount
11pm to 7:59am  40% discount            60% discount

Input
Day on which call made indicated as a single upper case letter (M for Monday, U for Tuesday, W for Wednesday, T for Thursday, F for Friday, A for Saturday, and S for Sunday)

Start time of call, using the 24-hour clock, as a four digit number (1:24pm would be input as 1324, Midnight would be input as 0000)
End time of call as above

NOTE No call can be longer than 10 hours duration

Output

For each call made
The day of the week, as a full name (eg Monday)
Call duration
Total Charge

On closure
Total number of calls made
Total duration of calls
Total cost of calls

NOTES
- All input data should be vetted for feasibility.
- The program should loop, accepting call details until manually terminated. You can decide how processing will be terminated.

So far i have managed to complete everything, BUT, i am not sure how to create discounts for certain call times on certain days..
Below is the code which i have created so far, any help would be gratefull!!

#include <cstdio>
#include <iomanip>
#include <iostream>

using namespace std;
char day, chday;
int call_start, duration, call_end, call_start_hrs, call_start_min, tot_call_start_min, call_end_hrs, call_end_min, tot_call_end_min;
float fullcost;

float input_data()

{
    day=false;

    cout<<"Please enter day...E.gvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv";
    cout<<"nn";
    cout<<"M = Monday";
    cout<<"nn";
    cout<<"U = Tuesday";
    cout<<"nn";
    cout<<"W = Wensday";
    cout<<"nn";
    cout<<"T = Thursday";
    cout<<"nn";
    cout<<"F = Friday";
    cout<<"nn";
    cout<<"A = Saturday";
    cout<<"nn";
    cout<<"S = Sunday";
    cout<<"nn";
    cout<<"nn";



    while (!day)

    {
        cin>>chday;
        cout<<"nn";


        if((chday=='M')||(chday=='U')||(chday=='W')||(chday=='T')||(chday=='F')||(chday=='A')||(chday=='S'))
        {
            day=true;
        }

        else

        {
            day=false;
            cout<<"!!Error!!...Please Enter A Valid Character";
            cout<<"nn";
        }

    }

switch(chday)

        {
        case 'M':
                cout<<"You Entered Monday";
                cout<<"nn";
                break;
        case 'U':
                cout<<"You Entered Tuesday";
                cout<<"nn";
                break;
        case 'W':
                cout<<"You Entered Wensday";
                cout<<"nn";
                break;
        case 'T':
                cout<<"You Entered Thursday";
                cout<<"nn";
                break;
        case 'F':
                cout<<"You Entered Friday";
                cout<<"nn";
                break;
        case 'A':
                cout<<"You Entered Saturday";
                cout<<"nn";
                break;
        case 'S':
                cout<<"You Entered Sunday";
                cout<<"nn";
                break;
        default: cout<<"Error";
            cout<<"nn";
        }


    return (0);

}


int input_times()

{

cout<<"nn";
cout<<"=============================================================";    
cout<<"nn";
cout<<"       ***** Times Of Calls *****";
cout<<"nn";
cout<<"Please Enter Start Time Of Your Call   ";
cin>>call_start;
cout<<"nn";
cout<<"nn";
cout<<"Please Enter End Time Of Your Call ";
cin>>call_end;
cout<<"nn";
cout<<"============================================================"; 
cout<<"nn";

return 0;
}



int total_call_time()
{

    call_start_hrs=(call_start/100);
    call_start_min=(call_start%100);

    tot_call_start_min=((call_start_hrs*60)+call_start_min);

    call_end_hrs=(call_end/100);
    call_end_min=(call_end%100);

    tot_call_end_min=((call_end_hrs*60)+call_end_min);


    duration=((tot_call_end_min)-tot_call_start_min);


return 0;
}


float charge_rate()

{
cout<<"       ***** Call Charges *****";
    cout<<"nn";
    double fullcost = 1.50;

    if(duration<=3)
    {
        fullcost=((1.50)*(duration));
    }
    else
    {
        fullcost=((0.30)*(duration));
    }

cout<<"Your Call Started At " <<call_start <<" Hundred hours";
    cout<<"nn";
cout<<"Your Call Ended At " <<call_end <<" Hundred hours";
    cout<<"nn";
cout<<"The Total Duration Of Your Call Is "<<duration <<" Minutes";
    cout<<"nn";
cout.setf(ios::fixed); 
cout<< setw(2) << setprecision(2)<<"The Total Cost Of Your Telephone Call Is " << fullcost <<" Pounds";
cout<<"nn";
cout<<"============================================================"; 

    cout<<"nn";


return 0;
}


int main()

{

input_data();
input_times();
total_call_time();
charge_rate();
system("pause");
return 0;
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

If you had a discount array, where every day was represented by the number of the row, and every column represented the hour of the day:

Sunday (row 0): 0 (midnight) 1 (0100) 2 (0200) 3 (0300), etc.
Monday (row 1): 0            1        2        3

Then each element could hold the discount applicable to that day and time.

Sunday (row 0): 0 (midnight) 1 (0100) 2 (0200) 3 (0300), etc.
Monday (row 1): 0 0.10 (10%) 1  0.08  2  0.05  3 0.04  , etc.

The key is the tie between day of the week and the row number, and hour of the day (after midnight) and the column number.

And Welcome to the forum, Steve! ;)

Edited 6 Years Ago by Adak: n/a

If you had a discount array, where every day was represented by the number of the row, and every column represented the hour of the day:

Sunday (row 0): 0 (midnight) 1 (0100) 2 (0200) 3 (0300), etc.
Monday (row 1): 0            1        2        3

Then each element could hold the discount applicable to that day and time.

Sunday (row 0): 0 (midnight) 1 (0100) 2 (0200) 3 (0300), etc.
Monday (row 1): 0 0.10 (10%) 1  0.08  2  0.05  3 0.04  , etc.

The key is the tie between day of the week and the row number, and hour of the day (after midnight) and the column number.

And Welcome to the forum, Steve! ;)

I can see what you are saying, but is it possible to give me an example of how to implement this in my code please... thanks

Although I don't fully understand the assignment, I will attempt to throw some code your way to help get the gears spinnin' inside ye' head.

based on your current coding style, i would suggest simple if/else logic:

//all calls will be at least E1.50
full_cost = 1.5;

//adjust call duration
if(call_duration > 3)
{
     call_duration -= 3;  //3 minutes
}

//enforce 10hr. limit
if(call_duration > 597)
{
     call_duration = 597;  //10hr. limit (minus 3min. initial charge) converted to minutes
}

//make rate determinations (calls made between 11pm to 8am ending before 5pm)
if(call_start >= 2300 && call_start <= 0800 && call_end <= 1659)
{
     //calculate reg. rate and apply 40% discount
     full_cost += (call_duration * .30) * .6;
}

//for calls made before 8am lasting longer than 5pm
else if(call_start >= 2300 && call_start <= 0800 && call_end <= 2259)
{
     //calculate reg. rate, apply 40% up until 5pm
     full_cost += ((1659 - call_start) * .30) * .6;
     //then apply 60% discount after 5pm
     full_cost += ((1700 + call_end) * .30) * .4;
}

/* 
     and so on and so forth, accounting for all the different call scenarios, but not accounting for calls that exceed 10 hours.
*/

This is not complete code but it is at least something to get you started.


This does not make sense to me, because it says you apply a discount, but then it says to apply another discount.. quite confusing:

Before 8am 40% discount 60% discount
8am to 4:59pm Regular charge rate 60% discount
5pm to 10:59pm 30% discount 60% discount
11pm to 7:59am 40% discount 60% discount

Edited 6 Years Ago by Clinton Portis: n/a

yes, if the call is between 8am and 4.59pm , Monday to Friday, 30% discount is given,,, if the call is made on Saturday or Sunday a 60% discount is given,
very confusing for me too as a beginner ...lol

Ah, that makes sense. Adjust the code to account for the given day.

I would recommend dedicating a variable that will identify a call as either weekday or weekend. I would probably make this a bool type variable. For this example, I'll call make it bool is_weekend, set to false if it is a weekday call and set to true if it is a weekend call:

//all calls will be at least E1.50
full_cost = 1.5;

//adjust call duration
if(call_duration > 3)
{
     call_duration -= 3;  //3 minutes
}

//enforce 10hr. limit
if(call_duration > 597)
{
     call_duration = 597;  //10hr. limit (minus 3min. initial charge) converted to minutes
}

//identify call as a weekday or weekend call
if(chday == 'A' || chday == 'S')
{
     is_weekend = true;
}
else
{
     is_weekend = false;
}

//make rate determinations (calls made between 11pm to 8am ending before 5pm)
if(call_start >= 2300 && call_start <= 0800 && call_end <= 1659)
{
     //weekday call
     if(!is_weekend)
     {
          //calculate reg. rate and apply 40% discount
          full_cost += (call_duration * .30) * .6;
     }
     //weekend call
     else
     {
          //calculate reg. rate and apply 60% discount
          full_cost += (call_duration * .30) * .4;
     }    
}

So on and so forth.

Edited 6 Years Ago by Clinton Portis: n/a

If you had a discount array, where every day was represented by the number of the row, and every column represented the hour of the day:

Sunday (row 0): 0 (midnight) 1 (0100) 2 (0200) 3 (0300), etc.
Monday (row 1): 0            1        2        3

Then each element could hold the discount applicable to that day and time.

Sunday (row 0): 0 (midnight) 1 (0100) 2 (0200) 3 (0300), etc.
Monday (row 1): 0 0.10 (10%) 1  0.08  2  0.05  3 0.04  , etc.

The key is the tie between day of the week and the row number, and hour of the day (after midnight) and the column number.

And Welcome to the forum, Steve! ;)

can you explane a little more please,, sorry for being a pain.. thanks

This question has already been answered. Start a new discussion instead.