I can’t figure out way i’m getting wrong answer. I’ve tested the program both with the sample input and a random input. Here’s the code.
#include <stdio.h>
int main(int argc, const char * argv[])
{
const int numberOfRounds = 5;
int playerOne[5], playerTwo[5];
for(int i = 0; i<numberOfRounds; i++){ //load users scores
int pOne = 0, pTwo = 0;
scanf("%d %d", &pOne, &pTwo);
playerOne[i] = pOne;
playerTwo[i] = pTwo;
}
int scoreOne = 0 , scoreTwo = 0;
for(int j = 0; j<numberOfRounds; j++){
if(playerOne[j] > playerTwo[j]) { //find difference between scores and keep highest difference according to each player
int score = playerOne[j] - playerTwo[j];
if(score > scoreOne) {
scoreOne = score;
}
}
else {
int score = playerTwo[j] - playerOne[j];
if(score > scoreTwo) {
scoreTwo = score;
}
}
}
if(scoreOne > scoreTwo) {
printf("%d %d \n", 1, scoreOne);
}
else {
printf("%d %d \n", 2, scoreTwo);
}
return 0;
}