It's look that there is only one link, but there are two links.
Anyway, here is the code from him/her:
Code:
#include <stdlib.h>
#include <stdio.h> //included libraries
#include <string.h>
typedef struct wages //variables used
{
char surname[20];
char first[20];
int emp_income; //Employee income per year
int taxcred; //tax credit
int YIT; //yearly income tax
int YTH; //yearly take home
} tax_info;
void file_output(tax_info tax);
int calc_YIT(int emp_income);
int calc_YTH(int emp_income, int YIT, int taxcred);
int user_menu();
int main () //main function
{
FILE* fp;
int tax_no = 0;
char ch;
tax_info wages[10000];
int option;
option = user_menu();
while (option != 4)
{
if (option == 1) //when user presses one, this initiates
{
fp = fopen("income.txt", "r"); //opens file with name indata.txt
while(!feof(fp)) //scans through the file
{
fscanf(fp, "%s%c%s%c%d%c%d%c", &wages[tax_no].surname, &ch, &wages[tax_no].first, &ch,
&wages[tax_no].emp_income, &ch, &wages[tax_no].taxcred, &ch);
printf("%s %s %d %d\n", wages[tax_no].surname,
wages[tax_no].first, wages[tax_no].emp_income,
wages[tax_no].taxcred);
//accesses get_offer function to calculate new price
wages[tax_no].YIT = calc_YIT( wages[tax_no].emp_income);
tax_no++;
wages[tax_no].YTH = calc_YTH( wages[tax_no].emp_income, wages[tax_no].YIT, wages[tax_no].taxcred);
tax_no++;
}
fclose(fp); //closes
}
else
{
int i;
for(i = 0; i < tax_no; i++) //structured array
{
if (option == 2) //when user presses 2, this initiates
{
printf("%s %s EUR %d EUR %d EUR %d \n", wages[i].surname,
wages[i].first, wages[i].emp_income, wages[i].YIT, wages[i].YTH); //prints results to screen
}
else if (option == 3) //when user presses 3, this initiates
{
file_output(wages[i]);
}
}
}
option = user_menu();
}
return (EXIT_SUCCESS); //return success
}
int user_menu() //function for the user menu
{
int option = 0;
while (option < 1 || option > 4) //loops through 1 - 4
{
printf("\n\tChoose An Option:\n");
printf("\t[1] Read Data From File\n");
printf("\t[2] Print Data In Memory On Screen\n");
printf("\t[3] Print Data In Memory To File\n");
printf("\t[4] Quit Program\n\n");
scanf("%d", &option);
printf("\n");
}
return option;
}
int calc_YIT(int emp_income){
int YIT;
if (emp_income < 32000){
YIT = 0.2 * emp_income;
}
else{
YIT = (0.2 * emp_income) + ((0.42) * (emp_income - 32000));
}
return YIT;
}
int calc_YTH(int emp_income, int YIT, int taxcred){
int YTH;
YTH = (emp_income + taxcred) - YIT;
return YTH;
}
void file_output(tax_info tax) //function for outputting file into a .txt file
{
FILE* fp;
fp = fopen("out2011.txt", "a");
fprintf(fp, "%s %s %d %d %d \n", tax.surname, tax.first, tax.emp_income, tax.YIT, tax.YTH);
fclose(fp);
return;
}
And this is the text file:
Code:
Moore Paul 30000 3120
ODonnell John 12000 3120
Murphy William 65000 4750
Bush Sean 45000 5000
Murphy Denise 15000 3500
OBrien Mary 100000 5000
OConnor Julia 16000 3500
Quinn Judy 25000 5000