Link to home
Start Free TrialLog in
Avatar of Jdub
Jdub

asked on

Help with source code!

I am trying to write a program in C that simulate the billing of a telephone company. It should calculate the length of the call and the cost of the call. I am haveing trouble with adding an array where the summary shows the start time and end time of each call per customer. ***For example, Call 1 started at 23:45 and ended at 0:15. The duration of call 1 is 30 minutes.*** Below is a copy of my code that I have currently. Can You Help?!?
Thanks

#include <stdio.h>
#define reg_rate 0.25
#define discount 0.10
#define tax_rate 0.08
#define pm_discount 0.40

double Total_Time(double);
double Call_Cost(double);
double cost[10];

double tax, total_cost, sub_total, sub_total1, sub_total2,
       grand_total, cust_total, total_time;

int    response, hrs, min, end_hrs, end_min, cust_count, call_count, time_total, cust_time, cust_call_count;

main()
{
printf("\n*******Eastern Atlantic Telephone company*******\n\n");
  cust_count = 0;
  call_count = 0;
  grand_total = 0;
  time_total = 0;
  cust_time = 0;
  cust_call_count = 0;

  printf("\nDo you have a customer to process?");
  printf("\nEnter 1 for yes or 0 for No: ");
  scanf("%d", &response);
   while (response == 1)
    {
     cust_time = 0;
     cust_total = 0;
     ++cust_count;
     cust_call_count = 0;

     printf("\nEnter the start time of the call: ");
     scanf("%d:%d", &hrs, &min);
      if ((hrs >= 24) || (hrs < 0) || (min >=60) || (min < 0 ))
       {
        hrs = 0;
        min = 0;
        printf("\nThe time entered is incorrect!");
        printf("\nEnter the start time of the call: ");
        scanf("%d:%d", &hrs, &min);
       }

   printf("Enter the end time of the call: ");
   scanf("%d:%d", &end_hrs, &end_min);
   if ((end_hrs >= 24) || (end_hrs < 0) || (end_min >=60) ||  (end_min < 0 ))
       {
        end_hrs = 0;
        end_min = 0;
        printf("\nThe time entered is incorrect!");
        printf("\nEnter the end time of the call: ");
        scanf("%d:%d", &end_hrs, &end_min);
       }

     ++cust_call_count;
     ++call_count;

     total_time = Total_Time(total_time);
     total_cost = Call_Cost(total_cost);
     cost[10] = total_cost;

     printf("\nThe duration for this call is %.2f minutes.", total_time);

     cust_total += total_cost;
     time_total += total_time;
     cust_time += total_time;

     printf("\nDo you have a another call to process?");
     printf("\nEnter 1 for yes or 0 for No: ");
     scanf("%d", &response);
      while (response == 1)
       {
        ++cust_call_count;
        ++call_count;

        printf("\nEnter the start time of the call: ");
        scanf("%d:%d", &hrs, &min);
         if ((hrs >= 24) || (hrs < 0) || (min >=60) || (min < 0 ))
          {
           hrs = 0;
           min = 0;
           printf("\nThe time entered is incorrect!");
           printf("\nEnter the start time of the call: ");
           scanf("%d:%d", &hrs, &min);
          }

        printf("Enter the end time of the call: ");
        scanf("%d:%d", &end_hrs, &end_min);
         if ((end_hrs >= 24) || (end_hrs < 0) || (end_min >=60) || (end_min < 0 ))
          {
           end_hrs = 0;
           end_min = 0;
           printf("\nThe time entered is incorrect!");
           printf("\nEnter the end time of the call: ");
           scanf("%d:%d", &end_hrs, &end_min);
          }

        total_time = Total_Time(total_time);
        total_cost = Call_Cost(total_cost);
        cost[10] = total_cost;
     printf("\nThe duration for this call is %.2f minutes.", total_time);


     time_total += total_time;
     cust_total += total_cost;
     cust_time += total_time;

     printf("\nDo you have a another call to process?");
     printf("\nEnter 1 for yes or 0 for No: ");
     scanf("%d", &response);
    }
  printf("\n******Customer Summary Report******");

  printf("\nThe total number of calls is %d.", cust_call_count);
  printf("\nThe total time for this customer is %d minutes.", cust_time);
  printf("\nThe total for theis customer is $%.2f", cust_total);

  grand_total += cust_total;

  printf("\nDo you have a customer to process?");
  printf("\nEnter 1 for yes or 0 for No: ");
  scanf("%d", &response);
 }
printf("\nThe Grand Total is $%5.2f.", grand_total);
printf("\nThe Total Number of calls is %d.", call_count);
printf("\nThe Total Time used by all customers is %d minutes.", time_total);
printf("\nThe Total Number fo customers is %d.", cust_count);
}

double Total_Time(double total_time)
{
 if ((end_min < min ) && (end_hrs > hrs))
  {total_time = ((end_min + 60) - min) + ((end_hrs - 1 - hrs) * 60);}
 else if ((end_min >= min) && (end_hrs >= hrs))
  {total_time = (end_min - min) + ((end_hrs - hrs) * 60);}
 else if ((end_min < min) && (end_hrs < hrs))
  {total_time = ((end_min + 60) - min) + (((end_hrs -1) - (hrs - 24)) * 60);}
 else if ((end_min > min) && (end_hrs < hrs))
  {total_time = (end_min - min) + ((end_hrs - (hrs -24)) * 60);}
 return total_time;
}

double Call_Cost(double total_cost)
{
 if ((hrs < 18) && (hrs>= 8) && (total_time >= 60))
  {
   sub_total = total_time * reg_rate;
   sub_total1 = sub_total - (sub_total * discount);
   tax = sub_total1 * tax_rate;
   total_cost = sub_total1 + tax;
  }
 else if ((hrs < 18) && (hrs >=8))
  {
   sub_total = total_time * reg_rate;
   tax = sub_total * tax_rate;
   total_cost = sub_total + tax;
  }
 else if ((hrs >= 18) && (total_time >=60))
  {
   sub_total = total_time * reg_rate;
   sub_total1 = sub_total - (sub_total * pm_discount);
   sub_total2 = sub_total1 - (sub_total1 * discount);
   tax = sub_total2 * tax_rate;
   total_cost = sub_total2 + tax;
  }
 else if ((hrs >= 18) || (hrs < 8))
  {
   sub_total = total_time * reg_rate;
   sub_total1 = sub_total - (sub_total * pm_discount);
   tax = sub_total1 * tax_rate;
   total_cost = sub_total1 + tax;
  }
 else if ((hrs < 8) && (total_time >= 60))
  {
   sub_total = total_time * reg_rate;
   sub_total1 = sub_total - (sub_total * pm_discount);
   sub_total2 = sub_total1 - (sub_total1 * discount);
   tax = sub_total2 * tax_rate;
   total_cost = sub_total2 + tax;
  }
 return total_cost;
}    

Avatar of ozo
ozo
Flag of United States of America image

What do you need help with?
What it your program doing wrong?
Can you post your code so we can see where the problem is?
Avatar of Jdub
Jdub

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of nil_dib
nil_dib

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial