Pair programming: The Golden Dot game

Source: Internet
Author: User

A. Game content

The Golden Dot game is a digital mini-game whose game rules are:

n students (n usually greater than ten), each writing a rational number between 0~100 ( excluding 0 or three ), to the referee, the referee calculates the average of all the numbers, and then times the 0.618(so-called golden partition constant) , the G value is obtained. The number of the submitted nearest to G(absolute value) of the students get n points, the farthest from the G students get-2 points, the other students get 0 points. after a few days of playing, we found some interesting phenomena, such as the golden dots moving down gradually.

Two. Program implementation function

Each time you enter n numbers, calculate the average and the G-point, the input number closest to the G students get N, the farthest from the G-2 points, the other students get 0 points . Print each round of G points with each student's respective scores. The end of the game will be the sum of the results of each output, you can see the first students victory.

Three. Program Module

1. Enter

The input is divided into two parts: the number of players and the number of innings, each player's data input. Using the double loop I, J controls the player input and the game number respectively, and the player's input data is stored sequentially in the array. The code is as follows:

printf ("Number of games:"); Andfor (i = 0; i<n; i++)
scanf ("%f", &s[i]); scanf ("%f", &s[i]);//input data
scanf ("%d", &n);
printf ("Game Wheel Number:");
scanf ("%d", &m);

2. Calculate G-Spot

First, the total number of player data to find out the average, and then the average value by 0.618 to get the G point. We use a function--count (float a[],int size) to calculate the total number of all player data, return the total number after the main function is averaged with the G point, and print the G point. The functions are as follows:

< Span lang= "ZH-CN" > float count (float a[],int size)
 {
 int i;
 float sum=0.0;
 for (i = 0; i<size; i++)
 {
  sum = sum + a[i];
 }
 return sum; < Span lang= "ZH-CN" >
}//sum function

A = sum/n;
printf ("Golden dot g=%f\n", 0.618*a);//Calculate G-Spot

3. Compare assignments

The game requires the player to enter the number to compare with the golden point, so we will enter the number of players in order to subtract from the obtained gold, and the result into the array, and then the number in the group to compare the maximum minimum value, in another array of the maximum value of the corresponding subscript assigned-2, the minimum value corresponding to the subscript n, the other This allows the player to record each round of the score. The code is as follows:

min = b[0];
max = b[0];
for (i = 0; i<n; i++)
{
if (b[i]<min)
min = B[i];
}
for (i=0; i<n; i++)
{
if (b[i] = = min)
C[i] = n;
Else
C[i] = 0;
}
for (i = 0; i<n; i++)
{
if (B[i]>max)
max = B[i];
}
for (i = 0; i<n; i++)
{
if (b[i] = = max)
C[i] =-2;
}
Put each person's score into the array C
for (i=0;i<n;i++)
{
Mun[i]=mun[i]+c[i];
}
Accumulate the results of everyone
printf ("********************\n* to be divided into: *\n");
for (i = 0; i<n; i++)
printf ("*%2d *\n", C[i]);
printf ("********************\n");
Output per round score

< Span lang= "ZH-CN" > 4. Output result

< Span lang= "ZH-CN" > printf ("********************\n* score for:          *\ n ");
     for (i = 0; i<n; i++)
  printf ("*        %2d        *\n ", C[i]);
  printf ("********************\n");
  //output per round of results
 }
 printf ("********************\n* must be divided into:         *\n ");
 for (i=0;i<n;i++)
    printf ("*       %2d         *\n ", Mun[i]);
 printf ("********************\n");
 }

Four. Running results

Pair programming: The Golden Dot game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.