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. I am haveing trouble with the arrays to print out the summary for each customer. The summary should print the start and end times for each call. My code is included. 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];
int    duration[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);

     cust_total += total_cost;
     cost[10] = cust_total;
     time_total += total_time;
     cust_time += total_time;
     duration[10] = cust_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);

     time_total += total_time;
     cust_total += total_cost;
     cost[10] = cust_total;
     cust_time += total_time;
     duration[10] = cust_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.", duration[10]);
  printf("\nThe total for this customer is $%.2f", cost[10]);

  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 rdf
rdf

what language?
Avatar of Jdub

ASKER

Edited text of question.
What the h@ck does any bill look like anymore, from what company to who?

Is it the bill that is to be paid?

Or the calculations needed to assess the call?

(the former needs some "appearance" enhancements, and both have their legal aspects, while the latter is more continual)

it's nearly obviouds that length = end of call - begin, give or take some rings and pauses.  But, where do you get the information on costs (handling midnight is extra credit)? from where to where? WHat feeds you the timing information? (may need time zone adjustments)?

Do you feed this info in from a tape, are their live transactions occurring between the Bells? Are there different rates? Is the charge for the first minute the same as for the last minute?

Is a call from Germany to Australia the same rate as a call from Paris to London? Or from Rome to Rome?
----------
With this little info, I'd start with the bill to the house. Go get one, change a number here and there, then write up some printing code to send the numbers towards the printed page (bill), like a 'report', skipping all the math that would never get done.
Avatar of Jdub

ASKER

Edited text of question.
Trusting you can handle the other parts, math, midnight tricks, and that is either done now or will be soon, the first appearance is that you do not want or should not want any numerics between the array brackets following the main() invocation.

This looks like you want to do like a 'for loop' for ten, exactly ten clients. From one to ten. Or, from the first customer to the last customer in words, or whatever.  Assuming also you'll do error handling, where for some reason you only had eight customers.

If that's close approx., then you only want a variable between the brackets. Once you invoke Main(). Not much time.  I'll have to check back later, I can't tell what variable, I think you're running at least two, one for customer, and one for call/for/this/customer.  

First look from the code is like you are only handing call #10 for cust #10.

I'll try closer look later, note to self, anyone else, my mention of variable for an array would have candidates like:

     ++cust_count;
     ++cust_call_count;
     ++call_count;

The Arrays:

  cost[10]     = cust_total;
  duration[10] = cust_time;


ASKER CERTIFIED SOLUTION
Avatar of SunBow
SunBow
Flag of United States of America image

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