Anyone in here who is really good in C-programming might be able to help me...I am so stressed out...I have to turn in this paper in about an hour and it does run, but still errors...can anyone can fix it for me, please? I would really appreciate your help...
I may not be able to come to this site several times, so, if you are really helpful, I would appreciate if you can mail that to me at: [email protected]
The question is:
TAX PROGRAM
A prominent senator recently pledged to greatly simplify the tax laws. His staff came up with the following plan:
1. The taxable income calculation is based on filing status. For filing status J (married filing jointly), taxable income is equal to gross income minus two standard deductions minus $1,000 for each exemption. For any other filing status, taxable income is equal to gross income minus one standard deduction minus $1,000 for each exemption. The standard deduction is $3,000. The maximum number of allowable exemptions is 12. Taxable income cannot be less than zero; if it is then set it equal to zero.
2. The tax rate is computed from the following table based on the filing status and the taxable income:
Filing status Taxable income Tax rate
Single less than $5,000 15%
$5,000 - $20,000 22%
more than $20,000 31%
Married less than $10,000 15%
$10,000 - $40,000 22%
more than $40,000 31%
Married filing less than $7,000 17%
Jointly $7,000 - 25,000 24%
More than $25,000 33%
3. The amount of tax due is the taxable income times the tax rate.
The program to implement this new tax plan should run in a loop. Each time through the loop it will read the following information form a text file:
Taxpayer ID (social security number) -- a long integer
Filing status -- a single character; must be 'S' for single, 'M' for married, 'J' for married filing jointly (upper or lower case). Validate incoming data, displaying an error message for records with an invalid filing status.
Gross income -- any floating number (negative allowed, representing a loss).
Number of exemptions -- an integer between 0 and 12, inclusive. Validate incoming data, displaying an error message for records with an invalid number of exemptions.
For each input record, validate the filing status and number of exemptions and produce an appropriate error message if necessary. For each valid input record, print out the taxpayer ID, taxable income, tax rate, and tax amount. Continue processing until the end of the input file is reached.
After processing all records, print a summary containing the number of taxpayers processed (both valid and invalid records should be included), the average tax amount (include valid records only), the highest tax amount (include valid records only), and the taxpayer ID of the highest tax amount.
Use the following data to test your program. Create the data as a text file on your disk.
Tax Program Input Data
Input file:
111111111S 7000 0
222222222M43500 4
333333333J28152 3
444444444X33509 0
555555555m82000 12
666666666J65197 6
777777777s29000 7
888888888s21543 15
999999999J54308 2
101010101S95602 1
121212121M18525 6
131313131j 8600 3
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sample Output: (Yours does NOT have to match this output exactly- but do include your name in the title; I just wanted you to be able to check your figures)
Your Name – Tax Table
Taxpayer ID Taxable Income Tax Rate Tax Amount
----------- -------------- -------- ----------
111111111 4000.00 0.15 600.00
222222222 36500.00 0.22 8030.00
333333333 19152.00 0.24 4596.48
444444444 **** Invalid filing status ****
555555555 67000.00 0.31 20770.00
666666666 53197.00 0.33 17555.01
777777777 19000.00 0.22 4180.00
888888888 **** Invalid number of exemptions ****
999999999 46308.00 0.33 15281.64
101010101 91602.00 0.31 28396.92
121212121 9525.00 0.15 1428.75
131313131 0.00 0.17 0.00
Number of Taxpayers Processed: 12
Number of Valid Taxpayers 10
Average Tax Amount 10083.85
Highest Tax Amount: 28396.62 for ID 101010101
And this is what I have done so far:
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *taxdata;
long ssn, highestPayer;
float gross, exemption, taxRate, taxableIncome, taxAmount, average=0, highestTax=0, total=0;
char status;
int numPayer=0, numProcessed=0;
taxdata=fopen("a:taxdata.txt","r");
if(taxdata==NULL)
{
printf("\nfailed to open.\n");
exit(1);
}
printf("\n Yog Panta Tax table\n\n");
printf("Taxpayer ID Taxable Income Taxrate Tax amount\n\n");
while(fscanf(taxdata, "%9ld %1c %5f %3f", &ssn, &status, &gross, &exemption)!=EOF)
{
switch(status)
{
case'S': case's':
taxableIncome=(gross-3000)-(1000*exemption);
if(exemption<0 || exemption>12)
{
printf("%ld *******Invalid number of exemption*************\n", ssn);
numPayer=numPayer-1;
break;
}
if(taxableIncome<0)
taxableIncome=0;
if(taxableIncome<5000)
taxRate=0.15;
if(taxableIncome>=5000&&taxableIncome<=20000)
taxRate=0.22;
if(taxableIncome>20000)
taxRate=0.31;
taxAmount=taxableIncome*taxRate;
printf("%ld $%8.2f %.0f%% $%8.2f\n", ssn, taxableIncome, taxRate*100, taxAmount);
break;
case 'M': case 'm':
taxableIncome=(gross-3000)-(1000*exemption);
if(exemption<0 || exemption>12)
{
printf(" %ld ************Invalid number of exemption\n***************", ssn);
numPayer=numPayer-1;
break;
}
if(taxableIncome<0)
taxableIncome=0;
if(taxableIncome<10000)
taxRate=0.15;
if(taxableIncome>=10000 && taxableIncome<=40000)
taxRate=0.22;
if(taxableIncome>40000)
taxRate=0.31;
taxAmount=taxableIncome*taxRate;
printf("%ld $%8.2f %.0f%% $%8.2f\n", ssn, taxableIncome, taxRate*100, taxAmount);
break;
case'J': case 'j':
taxableIncome=(gross-3000)*(2-1000*exemption);
if(exemption<0 || exemption>12)
{
printf("%ld *********Invalid number of exemption************\n", ssn);
numPayer=numPayer-1;
break;
}
if(taxableIncome<0)
taxableIncome=0;
if(taxableIncome<7000)
taxRate=0.17;
if(taxableIncome>=7000&&taxableIncome<=25000)
taxRate=0.24;
if(taxableIncome>25000)
taxRate=0.33;
taxAmount=taxableIncome*taxRate;
printf("%ld $%8.2f %.0f%% $%8.2f\n", ssn, taxableIncome, taxRate*100, taxAmount);
break;
default:
printf(" %ld ******Invalid filing status*********\n", ssn);
numPayer=numPayer-1;
}
numProcessed=numProcessed+1;
numPayer=numPayer+1;
total=total+taxAmount;
average=total/numPayer;
if(taxAmount>=highestTax)
{
highestTax=taxAmount;
highestPayer=ssn;
}
taxAmount=0;
}
fclose(taxdata);
printf("\nNumber of taxpayers processed---%d", numProcessed);
printf("\nAverage tax amount---$%5.2f", average);
printf("\n Highest tax amount---$%-5.2f for ID%ld\n", highestTax, highestPayer);
return 0;
}