|
-
Jan 29th, 2001, 03:58 PM
#1
Thread Starter
Hyperactive Member
I get errors when running this, please tell me whats wrong
#include <stdio.h>
void main(void)
{
int acct_num;
char use_code;
int peak_hrs;
int off_peak_hrs;
double charge;
float cost, cost2, total_cost;
void displayInstructions();
double computeCharge (char, int, int); /*declares function*/
FILE *in_file;
char f_name[13];
printf("\n file to be processed: ");
gets(f_name);
in_file = fopen (f_name, "r");
if (in_file == NULL)
{
printf("\n failed to open the file.\n");
exit (1);
}
while (fscanf(in_file, "%d %c %d %d ", &acct_num, &use_code, &peak_hrs, &off_peak_hrs) != EOF)
{
/*function called*/
charge = computeCharge(use_code, peak_hrs, off_peak_hrs);
if (charge == 0)
printf ("\n\n ACCT:%4d not processed. Invalid code entered:%c",acct_num, use_code);
else
printf ("\n ACCT#:%4d CUSTOMER CODE:%c", acct_num, use_code);
printf ("\n PEAK HRS:%4d OFF PEAK HRS:%4d",peak_hrs, off_peak_hrs);
printf ("\n TOTAL CHARGES:%4.2f \n",charge);
}
}
void displayInstructions()
{
char text;
FILE *IN_FILE;
in_file = fopen (text.dat, "r");
while (fscanf(in_file, " %c ", &text) != EOF)
{
printf("\n%c", text);
}
fclose(in_file);
}
/*computing charge function based on file input*/
double computeCharge(char x, int y, int z)
{
double charge;
float cost, cost2;
if (x == 'R' || x == 'r')
{
charge = ((y * 0.052) + 6.00);
}
else if (x == 'C' || x == 'c')
if (y > 1000)
{
charge = ((y - 1000) * 0.045) + 60.00;
}
else
{
charge == 60.00;
}
else if (x == 'I' || x == 'i')
{
if (y == 0 && z == 0)
{
charge = 10;
}
else if (y > 0 && z < 1000)
{
cost = 76;
if (z > 0 && z < 1000)
{
cost2 = 40;
}
else if (z > 0 && z > 1000)
{
cost2 = ((z - 1000) * 0.028 + 40);
}
charge = cost + cost2;
}
else if (y > 0 && y > 1000)
{
cost = ((y - 1000) * 0.065 + 76);
if (z > 0 && z < 1000)
{
cost2 = 40;
}
else if (z > 0 && z > 1000)
{
cost2 = ((z - 1000) * 0.028 + 40);
}
charge = cost + cost2;
}
}
else
{
charge = 0;
}
return (charge);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|