99,283 views
0 votes
0 votes
Write a program that completes the following requirements in C program:

opens a file called "salaries.txt" for reading

reads in four quarterly dollar salary payments from the file

sums the quarterly payments

determines the tax bracket à < $15,000 = low income; $15,000 - $200,000 = medium income; > $200,000 = high income

closes "salaries.txt"

displays ‘l’ for low income, ‘m’ for medium income, and ‘h’ for high income

User Laoujin
by
3.0k points

1 Answer

1 vote
1 vote

Answer:

#include<stdio.h>

#include<string.h>

int main() {

int n;

FILE *fp = fopen("salaries.txt", "r");

double sumSalaries = 0;

double quarterlySalary1, quarterlySalary2, quarterlySalary3, quarterlySalary4;

while(!feof(fp)) {

fscanf(fp, "%lf", &quarterlySalary1);

fscanf(fp, "%lf", &quarterlySalary2);

fscanf(fp, "%lf", &quarterlySalary3);

fscanf(fp, "%lf", &quarterlySalary4);

sumSalaries = sumSalaries + quarterlySalary1+quarterlySalary2+quarterlySalary3+quarterlySalary4;

printf("Salary Sum %lf: \\", sumSalaries);

printf("Income Type: ");

if(sumSalaries > 200000 ){

printf("h");

}

else if(sumSalaries >= 15000 && sumSalaries<=200000){

printf("m");

}

else{

printf("l");

}

printf("\\");

}

fclose(fp);

return 0;

}

Step-by-step explanation:

User Honzas
by
3.3k points