My code is down below. I trying to get an output from this input file input.txt.
This is a golf game and the first row is the number of golfers,
second row is the par and the last two rows are the players scores.
The breakdown is how the player scored in each hole.
2
3 4 4 4 4 5 5 3 3 4 4 4 4 4 5 3 3 4
4 4 5 4 6 4 5 6 3 4 4 4 5 4 3 3 5 4
2 3 4 4 4 5 5 3 3 4 4 4 4 4 4 3 3 4
My output should be
Player 1 scored 7.
Breakdown: 1 0 1 0 2 -1 0 3 0 0 0 0 1 0 -2 0 2 0
Player 2 scored -3.
Breakdown: -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0
Player 2 is the winner!
Im getting an output like this
player 1 score -1
Breakdown: 7290888
player 2 score -2
Breakdown: 7290888
Can anyone help?? please?
Code:
#include <stdio.h>
int main() {
FILE *ifp;
int golfer, counter, par[18], i, j, score=0, player[4][18], breakdown[18];
//Opening input file.
ifp = fopen("input.txt","r");
//Getting amount of players.
fscanf(ifp, "%d", &golfer);
//Calculating the par.
for(i = 0; i < 18; i++) {
fscanf(ifp, "%d", &par[i]);
}
for(counter = 0; counter < golfer; counter++) {
//Getting the players' scores.
for(i = 0; i < golfer; i++){
for(j = 0; j < 18; j++){
fscanf(ifp, "%d", &player[i][j]);
}
}
for(i = 0; i < golfer; i++){
//Calculating the breakdowns and score.
for(j = 0; j < golfer; j++){
breakdown[j] = player[i][j] - par[i];
score += breakdown[j];
}
}
//Printing the scores.
printf("Player %d Score: %d.\n", counter+1, score);
printf("Breakdown: %d.\n\n", breakdown[j]);
}
return 0;
}