I have this code but , doesn't print on the file,  so can you figure the error the code is  #include #include void charges (int usage , double *cost,double *avg); double round (double money); int main() { int id,month, year;    double usage, cost , avg;    FILE *fin ,*fout;    fin = fopen("usage.txt","r");    fout= fopen("charge.txt","w");    fscanf(fin,"%d,%d",&month,&year);    double valid = fscanf (fin,"%d,%lf",&id,&usage);    while(valid != EOF)    {     valid = fscanf (fin,"%d,%lf",&id,&usage);     charges (usage,&cost,&avg);     double roundcost=round(cost);     double roundavg=round (avg);     fprintf(fout,"charges for %d\\%d",&month,&year);    fprintf(fout,"%d %f %0.2f %0.2f",id,usage,cost,avg);      }      fclose(fin);    fclose(fout);     return 0; } void charges (int usage , double *cost,double *avg) { double money=0;     if (usage <= 10)     {         *cost=7.99;     }     else     {         *cost = (usage-10)*1.99+7.99;     }     *avg=*cost/usage;     money =*cost;     *cost=round(money);     money=*avg;     *avg=round(money); }   double round (double money) {     money=money*100;     money=round(money);     money=money/100;     return money; } The original question is , note we have to use two functions,  pointer , file , we aren't allowed to use arrays  (Wattan Corporation) is an Internet service provider that charges customers a flat rate of $7.99 for up to 10   hours of connection time. Additional hours or partial hours are charged at $1.99 each.   Write a function charges that computes the total charge for a customer based on the number of hours of connection time used in a month. The function should also calculate the average cost per hour of the time used (rounded to the nearest 0.01), so use two output parameters to send back these results.   You should write a second function   round_money that takes a real number as an input argument and returns as the function value the number rounded to two decimal places. Write a main function that takes data from an input file usage.txt and produces an output file charges.txt. The data file format is as follows:   Line 1: current month and year as two integers   Other lines: customer number (a five-digit number) and number of hours used   Here is a sample data file and the corresponding output file:   Data file usage.txt 10 2009   15362 4.2   42768 11.1   11111 9.9   Output file charges.txt   Charges for 10/2009 15362 4.2 7.99 1.90 42768 11.1 10.18 0.92 11111 9.9 7.99 0.81

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I have this code but , doesn't print on the file,  so can you figure the error the code is 

#include <stdio.h>

#include <stdlib.h>

void charges (int usage , double *cost,double *avg);

double round (double money);

int main()

{ int id,month, year;

   double usage, cost , avg;

   FILE *fin ,*fout;

   fin = fopen("usage.txt","r");

   fout= fopen("charge.txt","w");

   fscanf(fin,"%d,%d",&month,&year);

   double valid = fscanf (fin,"%d,%lf",&id,&usage);

   while(valid != EOF)

   {

    valid = fscanf (fin,"%d,%lf",&id,&usage);

    charges (usage,&cost,&avg);

    double roundcost=round(cost);

    double roundavg=round (avg);

    fprintf(fout,"charges for %d\\%d",&month,&year);

   fprintf(fout,"%d %f %0.2f %0.2f",id,usage,cost,avg);

 

   }

 

   fclose(fin);

   fclose(fout);

    return 0;

}

void charges (int usage , double *cost,double *avg)

{ double money=0;

    if (usage <= 10)

    {

        *cost=7.99;

    }

    else

    {

        *cost = (usage-10)*1.99+7.99;

    }

    *avg=*cost/usage;

    money =*cost;

    *cost=round(money);

    money=*avg;

    *avg=round(money);

}

 

double round (double money)

{

    money=money*100;

    money=round(money);

    money=money/100;

    return money;

}

The original question is , note we have to use two functions,  pointer , file , we aren't allowed to use arrays 

(Wattan Corporation) is an Internet service provider that charges customers a flat rate of $7.99 for up to 10

 

hours of connection time. Additional hours or partial hours are charged at $1.99 each.

 

Write a function charges that computes the total charge for a customer based on the number of hours of connection time used in a month. The function should also calculate the average cost per hour of the time used (rounded to the nearest 0.01), so use two output parameters to send back these results.

 

You should write a second function

 

round_money that takes a real number as an input argument and returns as the function value the number rounded to two decimal places. Write a main function that takes data from an input file usage.txt and produces an output file charges.txt. The data file format is as follows:

 

Line 1: current month and year as two integers

 

Other lines: customer number (a five-digit number) and number of hours used

 

Here is a sample data file and the corresponding output file:

 

Data file usage.txt 10 2009

 

15362 4.2

 

42768 11.1

 

11111 9.9

 

Output file charges.txt

 

Charges for 10/2009

15362 4.2 7.99 1.90

42768 11.1 10.18 0.92

11111 9.9 7.99 0.81

 

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education