• C

This is for AlexVirochovsky!

I am working with the code that you provided me from my last question.  I wanted ask you if you know why the program only compiles one time. I opened the program and compiled it. Then I closed it and reopened it again and it would not compile. The error I got was  declartion not allowed here in funciton main.  The error points to this line:
FILE *fIn  = fopen(szNameI,"rt");

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define discount 0.15
#define full_price 0.25
#define fed_tax 1.08
#define TRUE 1
#define FALSE 0

int Minutes(int s_hour, int s_minute, int e_hour, int e_minute,int *start);
void Customer_Summary(int call_count, long customer_time,double customer_charge);
double Bill(double c_time, int s_time);
void Total_Summary(int, int, double, double, double);
//1-st par: name of input,2-nd name of out
void main(int num, char *var[])
   char szNameI[255],szNameO[255];

   int total_calls = 0,
       total_customers = 0;

       long total_minutes = 0;
       double total_amount =0,total_charge = 0;
    double total_tax =0;

   if (num <= 1)

   if (num <= 2)
FILE *fIn  = fopen(szNameI,"rt");
      if (fIn)
FILE *fOut = fopen(szNameO,"wt");
while (!feof(fIn))
     char buff[81],szName[81],ac[10],phon[10];
     int number,i,hs,ms,he,me,start;
     double customer_charge = 0;
     long customer_duration = 0;

     if (!fgets(buff, sizeof(buff)-1, fIn))//1-st field: name
     strtok(buff, "\n"); //delete /n
     strcpy(szName,buff); //form name
     if (!fgets(buff, sizeof(buff)-1, fIn))//
break;//2-nd field: number
     number = atoi(buff);
        printf("\nCall                Start time    Ending time   Duration    Charge");
        for (i = 0; i < number; i++)
int start,duration;
double charge;

fgets(buff, sizeof(buff)-1, fIn);//next field: number + time
strtok(buff, "\n"); //delete /n
sscanf(buff,"%s %s %d:%d %d:%d",ac,phon,&hs,&ms,&he,&me);
duration = Minutes(hs,ms,he,me,&start);
charge = Bill(duration, start);
printf("\n %s %s         %02d:%02d          %02d:%02d %9d %11.2f",ac,phon,hs,ms,he,me
,duration, charge);
customer_charge += charge;
customer_duration += (long)duration;
     total_calls += number;
     total_minutes += customer_duration;
     total_tax += customer_charge * .08;
     total_charge += customer_charge;

     Customer_Summary(number, customer_duration, customer_charge);
      total_amount = total_charge*1.08; //???
      Total_Summary(total_customers, total_calls, total_minutes, total_amount, total_tax);

int Minutes(int s_hour, int s_minute, int e_hour, int e_minute,int *start)
      int iStart = s_hour *24 + s_minute;
      int iEnd   = e_hour *24 + e_minute;

   if (iStart > iEnd)
     iEnd += 24*60;
   *start = iStart;
   return iEnd - iStart;
// s_time: start time
// c_time: duration
//return money
double Bill(double c_time, int s_time)
  double charge;

  if ( (s_time > 8) || (s_time < 18) )
      charge = full_price * c_time;
      if (c_time > 60)
charge -= charge * 0.1;
      charge = discount * c_time;
      if (c_time > 60)
charge -= charge * 0.1;
  return charge;

void Customer_Summary(int call_count, long customer_time,double customer_charge)
  printf("\n\nThe total number of calls is:          %d", call_count);
  printf("\nThe total time used in minutes is:      %ld", customer_time);
  printf("\nThe total charge is:                    $%.2f", customer_charge);
  printf("\nThe total tax is:                      $%.2f", customer_charge * .08);
  printf("\nThe total amount due is:               $%.2f", customer_charge + (customer_charge * .08));

void Total_Summary(int total_customers, int total_calls, double total_minutes,
   double total_amount, double total_tax)
  printf("\nTOTAL SUMMARY\n");
  printf("\nThe total number of customers:     %d", total_customers);
  printf("\nthe total number of calls is:      %d", total_calls);
  printf("\nThe total amount of time is:       %.0f", total_minutes);
  printf("\nThe total amount is:               $%.2f", total_amount);
  printf("\nthe total tax is:                  $%.2f", total_tax);
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What translator do you use?
May be it is simple "C".
In this case
1. After
>>void main(int num, char *var[])
   FILE *fIn;
2. instead of
>>   FILE *fIn  = fopen(szNameI,"rt");
   fIn  = fopen(szNameI,"rt");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.