Hi, i have written a program for my assignment, however i need a little bit of help..
the program is written in c++ and im using the bloodshed compiler - www.bloodshed.net
i need to put some kind of validation in whereby - it calculates the duration of a call in minutes (done the calculation) but if the duration of a call is longer than 600 mins (10 hours) then it should give an error message and take you back to the beginning of the program - pasted below is the complete code for the program i have.. just the calculations for the calls are not working for some reason - if someone can have a look at these for me i'd be very grateful
#include <stdio.h>
const float hi_rate=1.50;
const float lo_rate=0.30;
const float max_dur=600;
const float wkday_disc=0.4;
const float wkend_disc=0.6;
char day;
int st_hr, end_hr, st_min, end_min, call_dur, total_calls, total_dur;
float call_cost, total_cost;
main()
{
/* Set all counters to zero, needed to calculate total summary */
total_calls=0;
total_dur=0;
total_cost=0;
printf("\n\t\tEnter The Day: ");
scanf("%c",&day);
/* Program control loop - program ends if 'x' is entered */
while (day != 'x')
{
/* Input call start and end times */
printf("\n\t\tEnter Call Start Hour: ");
scanf("%d",&st_hr);
printf("\n\t\tEnter Call Start Minute: ");
scanf("%d",&st_min);
printf("\n\t\tEnter Call End Hour: ");
scanf("%d",&end_hr);
printf("\n\t\tEnter Call End Minute: ");
scanf("%d",&end_min);
getchar();
/* Calculate call duration */
call_dur=(end_hr - st_hr)*60 + end_min - st_min;
if (call_dur > max_dur)
printf("\n\t\tTime not valid");
/* Calculate call costs */
if (call_dur <= 3)
call_cost = hi_rate;
else
if (call_dur > 3)
call_cost = (call_dur-3)*lo_rate + hi_rate;
else
if (st_hr <= 7 || st_hr >= 17)
call_cost = ((call_dur*lo_rate) + hi_rate)*wkday_disc;
else
if (day =='a' || day=='s')
call_cost = ((call_dur*lo_rate) + hi_rate)*wkend_disc;
/* Calculate totals summary */
total_calls = total_calls + 1;
total_dur = total_dur + call_dur;
total_cost = total_cost + call_cost;
/* Switch used to display the day */
switch (day)
{
case 'm':
printf("\n\t\tCall made on - Monday");
break;
case 'u':
printf("\n\t\tCall made on - Tuesday");
break;
case 'w':
printf("\n\t\tCall made on - Wednesday");
break;
case 't':
printf("\n\t\tCall made on - Thursday");
break;
case 'f':
printf("\n\t\tCall made on - Friday");
break;
case 'a':
printf("\n\t\tCall made on - Saturday");
break;
case 's':
printf("\n\t\tCall made on - Sunday");
break;
default:
printf("\n\t\tDay Not Recognised");
break;
}
/* Displays summary of current call */
printf("\n\t\tDuration of call was %d minutes ",call_dur);
printf("\n\t\tCost of call was %4.2f ",call_cost);
printf("\n\n\t\tEnter The Day: ");
scanf("%c",&day);
}
/* Displays total summary of program run */
printf("\n\t\tTotal number of calls: %d ",total_calls);
printf("\n\t\tTotal duration of calls: %d minutes",total_dur);
printf("\n\t\tTotal cost of calls: %4.2f ",total_cost);
getchar();
getchar();
}
many thanks in advance