Dance Competition Application in C

Mustafa Serdar Konca
5 min readAug 21, 2020

--

Let’s imagine we have a dance competition. The user will determine the number of competitors in this competition. There will be 10 referees in the competition. These referees will give each competitor a score between 1 and 10. These points will be awarded randomly.

Requirements

  • For the 1st competitor, the score awarded by the 1st referee will be considered void.
  • For the 2nd competitor, the score awarded by the 3rd referee will be considered void
  • For the 3rd competitor, the score awarded by the 7th referee will be considered void
  • For the remaining competitors, the score of all 10 referees will count.
  • The dancers’ information (competitors’ information)(such as republic of Turkey ID, name, city) will be kept in struct.
  • The total scores of the dancers will be calculated and kept in a dynamic array.
  • Calculation of the dancers’ total scores must be in the “Total Score” function.
  • The total scores of the dancers must be in descending order.
  • After this ranking, the information of the first three competitors (together with their total scores) will be written to the file named “score.txt”.
  • Use the pointer offset method for the operations performed on the array.
The Our Project

If we look at the work we will do from a bird’s eye view, it will consist of 7 functions in total.

Now, we will examine these seven functions one by one.

First of all we have an global variable (int totalScoreRelay). We will use this later.

We start the project by creating an struct where we will keep the dancer information ( republicofTurkeyID, name, etc.).

We will go over the main functions and explain our other functions when necessary.

We write articles that will meet the user first in the application. And we ask the user how many competitors will enter in total. Because we’re going to create an dynamic array based on this number.

We create struct and open the necessary files to fulfill the requirements mentioned above.

Now we have the for loop, where we will do many operations on dancers. Of course, we restrict this for loop to the number of dancers we get in the first place. And here our function, which we will explain first, meets us.

This is a void function, so we don’t expect it to return a value. A simple function, its purpose is to take the dancer information and pass it to the struct structure.

Now we got the dancer information, now it’s time to collect the scores given by each jury. At this point, the apple function comes into play with our help. Of course, we first create a variable that will keep the total score of each of our competitors and set it equal to zero (totalDancerPoints). Now let’s move on to the apple function.

First, we start the function with a for loop. Of course, this cycle will repeat 10 times since we have 10 referees. Then, with if blocks, we deal with the invalidity of some referee scores that were fired from us. Thanks to this method, we can easily neutralize the referee we want for the dancer we want.
Of course, let’s not forget that the c language starts from zero.

This point is actually the most important part of our application. The referees first randomly score between one and ten and we print it on the screen. Then, every time this process happens, we collect it with sumPoints and transfer it to totalScoreRelay for future transfer. We print out the total score of a dancer and leave the function.

Let’s go back to the main function. We transfer all the information in the sumPoint function to the struck structure we created at the beginning in the main function. And as requested from us, we print this information in the dancersInfo file. And we keep total score information in totalScoreHolder for future use.

That future came because we were also asked to rank these scores in descending order. For this, we will use the scoreRankFromLargeToSmall function. So now it’s time to explain this function.

The basis of this function is actually based on the bubble sort algorithm. I will not explain this algorithm so that the article is not too long. But you can find its explanation very easily.

Let’s go back to the main function. We are now coming towards the end of our application. We listed the total scores of all dancers in the previous step. Now we have to find out which dancer got which score among them and determine the top three. And we have to print them to file. Then we exit the application.
Then we first print out the scores of all the dancers on this step. then we will call firsDancerPointesPrinter function.

I will only explain the function that finds the first one because the other two functions are almost identical. First of all, we open the file with the dancer information and get the information. Then we check if it is equal to the score in the 1st array (yourTotalScoreHolder), that is, the score with the highest score. If they’re equal, we print the first three on another text document.
And we exit the function.

Screenshots:

The First Informations
The Dancers Informations Text File
The Top 3 Dancers İnformations Text File

Congratulations, you have made a very nice competition application.

Files of everything we do here :

See you next time. Take care of yourself :)

--

--