Showing posts with label Program to Open a file. Show all posts
Showing posts with label Program to Open a file. Show all posts

Program to Open a file, read a file and write to a file

#include
int main()
{
float sales , commission;
FILE *fin, *fout;
fin = fopen("c:\\pop.dat","r");
fout = fopen("c:\\pop2.dat","w");
while (fscanf(fin,"%f",&sales) != EOF)
{
fprintf(fout,"Your sales for the year were %8.2f \n",sales);
if(sales < 30000)
commission = sales / 100 * 5;
else
commission = sales / 100 * 10;
fprintf(fout,"Your commission is %8.2f",commission);
}
return 0;
}

Labels