I'm doing this homework where I need to read a line from a file for each iteration.
I got this inputs:
200 38
220 48
230 68
240 48
260 68
280 68
300 48
0 0
What I need is to read the first 2 ints using fscanf.
Then on the next loop I'll read the next 2 ints and so on.
Ex. i'll read 200 38
then i'll read 220 48 on the next loop.
Can somebody help me with this?
#include <stdio.h>
int main() {
int rate, hours;
float pay;
// This program will compute the pay rate of a person based on the working hours.
FILE *inputFileptr;
FILE *outputFileptr;
inputFileptr = fopen("input.txt","rt");
outputFileptr = fopen("pays.txt","at");
do {
fscanf(inputFileptr,"%d %d", &rate, &hours);
if ( hours <= 40 ) {
pay = (hours * rate) / 100.00;
fprintf(outputFileptr,"Pay at %d centavos/hr for %d hours is %.2f pesos \n", rate, hours, pay);
}
else if ( hours <= 60 && hours > 40) {
pay = ((((hours - 40)* rate) * 1.5) + ( rate * 40)) / 100.00;
fprintf(outputFileptr,"Pay at %d centavos/hr for %d hours is %.2f pesos \n", rate, hours, pay);
}
else if ( hours < 60 ) {
pay = ((((hours - 60) * rate) * 2) + (((hours - 40)* rate) * 1.5) + (rate * 40));
fprintf(outputFileptr,"Pay at %d centavos/hr for %d hours is %.2f pesos \n", rate, hours, pay);
}
} while ( rate == 0 && hours == 0);
fclose(inputFileptr);
fclose(outputFileptr);
return 0;
}