• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

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

0
Jdub
Asked:
Jdub
1 Solution
 
ozoCommented:
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?
0
 
JdubAuthor Commented:
Edited text of question.
0
 
nil_dibCommented:
the problem are the two lines:

cost[10] = total_cost;

you declared cost as an array of 10(!!) doubles, but the line
cost[10] = total_cost;
accesses the 11 element of the array (to access the 10 element: cost[9] beginning with 0 until 9)!!!

feel free to ask if you need further information.

nil_dib
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now