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;
}