/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#define MIN_SCORE 0
#define MAX_SCORE 450
#define MIN_PLAYERS 0
#define MAX_PLAYERS 2000
int
main ()
{
int topScore[MAX_PLAYERS];
int numPlayers;
float sum;
int placeHolder1;
int frequnecy[MAX_PLAYERS];
//Corrections below in 2 for loops to init all data
for (int i = 0; i < MAX_PLAYERS; i++)
{
frequnecy[i] = 0;
}
for (int i = 0; i < MAX_PLAYERS; i++)
{
topScore[i] = 0;
}
//Corrections below in 2 for loops to init all data -- END
printf ("Please enter how many players there are\n");
do
{
scanf ("%i", &numPlayers);
if (numPlayers > MAX_PLAYERS || numPlayers < MIN_PLAYERS)
printf ("Invalid please try again\n");
else
printf ("There are %i players\n", numPlayers);
}while (numPlayers > MAX_PLAYERS || numPlayers < MIN_PLAYERS);
for (int i = 0; i < numPlayers; i++)
{
printf ("Enter score betweem 0 and 450 for person %i\n", i + 1);
do
{
scanf ("%i", &topScore[i]);
if (topScore[i] > 450 || topScore[i] < 0)
{
printf("Invalid please enter a number between 0 and 450 for person %i\n", i + 1);
frequnecy[i] = -1; //?? n0t reqd here , i think
}
} while (topScore[i] > MAX_SCORE || topScore[i] < MIN_SCORE);
}
#if 1
for (int i = 0; i < numPlayers; i++)
{
printf ("Player %i scored %d\n", i + 1, topScore[i]);
}
sum = 0;
for (int i = 0; i < numPlayers; i++)
{
sum = sum + topScore[i];
}
printf ("The average top score was %.1f \n\n", sum / numPlayers);
for (int i = 0; i < numPlayers; i++)
{
placeHolder1 = 1;
for (int j = i + 1; frequnecy[topScore[i]] ==0 && j < numPlayers; j++){
if (topScore[i] == topScore[j])
{
placeHolder1++;
//frequnecy[j] = 0;
}
}
if ( frequnecy[topScore[i]] ==0 )
{
frequnecy[topScore[i]] = placeHolder1;
}
}
printf ("%5s", "Top Score");
printf ("%20s", "Frequnecy\n");
for (int i = 0; i < MAX_PLAYERS; i++)
{
if (frequnecy[i] != 0)
{
printf ("%d occurs %d times\n", i, frequnecy[i]);
}
}
#endif
}