Hey guys,
I'm stuck on a tax program. First i need to use a loop to generate 10 incomes and save them in an array. Then use a loop to calculate the tax and save the taxes in another array. After calculating all the taxes, i have to write the output to a file.
This is what i have so far... (I got it to run but i dont know how to loop the scanf)
Code:
#include <stdio.h>
#include <math.h>
void main (void)
{
int i, j, k, num_elem;
double tax, x[9], y[9], z[9];
FILE *outfile;
printf ("Type in your ten incomes\n");
outfile= fopen("a6q1.out","w");
scanf ("%lf", &x[0]);
fprintf (outfile, "Value of EOF = %d\n", EOF);
while (x[i] != EOF) i++;
num_elem = i;
fprintf(outfile,"x[i]\n");
for (j=0; j<num_elem; j++)
{
if(x[j]<1000)
{
tax=0;
printf("%.2lf %.2f", x[j], tax);
}
else if(x[j]>=2000)
{
tax=x[j]*0.30;
printf("%.2lf %.2f", x[j], tax);
}
else
{
tax=x[j]*0.20;
printf("%.2lf %.2f", x[j], tax);
}
}
fclose(outfile);
}
Any help would be greatly appreciated. Thanks!