hello, i am a C beginner.
please check the code for me.
The program is running fine,but is not giving the correct output or should is say no output. The output supposed to give the code of the team that ranked higher.
#include <stdio.h>
char rankTeams(int, int, int, int, char, int, int, int, int, char);
int getsPoints(int, int);
char highestGoalsFor(int, char, int, char);
char determineHigherGoalDifference(int, int, char, int, int, char);
int main()
{
char code, code2, highest;
int won, won2, drawn, drawn2, goalsFor, goalsFor2, goalsAgainst, goalsAgainst2, points, points2, goalDiff;
printf("Enter the name and statistics for the first team: n ");
scanf("%s %d %d %d %d", &code, &won, &drawn, &goalsFor, &goalsAgainst);
printf("Enter the name and statistics for the second team: n ");
scanf("%s %d %d %d %d", &code2, &won2, &drawn2, &goalsFor2, &goalsAgainst2);
rankTeams(won, drawn, goalsFor, goalsAgainst, code, won2, drawn2, goalsFor2, goalsAgainst2, code2);
printf("Team %c is the highest ranked team. n", highest);
return 0;
}
char rankTeams(int won, int drawn, int goalsFor, int goalsAgainst, char code, int won2, int drawn2, int goalsFor2, int goalsAgainst2, char code2)
{
int points, points2, highGD;
char highest;
points = getsPoints(won, drawn);
points2 = getsPoints(won2, drawn2);
if (points == points2)
{
highest = determineHigherGoalDifference(goalsFor, goalsAgainst, code, goalsFor2, goalsAgainst2, code2);
printf("Team %c is the highest ranked team", highest);
}
else if (points > points2 )
highest = code;
else
highest = code2;
return highest;
}
int getsPoints(int won, int drawn)
{
int points;
points = (won * 3) + drawn;
return points;
}
char highestGoalsFor(int goalsFor, char code, int goalsFor2, char code2)
{
char highest;
if (goalsFor > goalsFor2)
highest = code;
else if (goalsFor < goalsFor2)
highest = code2;
else
printf("Team %c is ranked the same as team %c. n", code2, code);
return highest;
}
char determineHigherGoalDifference(int goalsFor, int goalsAgainst, char code, int goalsFor2, int goalsAgainst2, char code2)
{
int goalDiff;
char highGD;
goalDiff = (goalsFor - goalsAgainst) - (goalsFor2 - goalsAgainst2);
if (goalDiff == 0)
highGD = highestGoalsFor(goalsFor, code, goalsFor2, code2);
else if (goalDiff > 0)
highGD = code;
else
highGD = code2;
return highGD;
}