Golden Dot Game Introduction Description:
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.
Program ideas: 1. Using the For loop, scanf Enter the number of people you can participate in and the input values for each person;
2. Determine whether each person's input value is legal, if no, please re-enter, i--;
3. Find the golden point and use the Fabs function to assign the resulting value to a new array b[];
4. Use the For loop again to find the maximum and minimum value, and to find out the value of the lower corner mark I, and print it out;
5. End the loop and print each result.
Here are the notes and ideas for each small program:
#include"stdafx.h"#include"stdio.h"#include"string.h"#include"math.h"voidGameguide ();//Game Introduction DescriptionvoidGamebegin ();//Game StartvoidGameover () {printf ("Thank you for your use, we'll be seeing you again.");};
function definition and description of the header file;
voidMainintargcChar*argv[]) { intN; printf ("********** Welcome to the Golden Dot game ******************\n");/*game interface for the entire program*/printf ("**********1 Game Instructions **************\n"); printf ("**********2 start Game ****************\n"); printf ("**********3 Game Over ***************\n"); while(1) {scanf ("%d",&N); Switch(n)//invoking a function using the switch function { Case 1: Gameguide (); Break; Case 2: Gamebegin (); Break; Case 3: Gameover (); Break; } }}
This program is a single machine, the design of the game interface and the use of switch function to call the function;
printf"the number of people you choose to join is: \ n"); scanf ("%d", &z);//Number of participantsprintf"Please select the number of participants: \ n"); scanf ("%d",&h); for(j=1; j<=h;j++)//Number of participants { for(i=1; i<=z;i++) {printf ("the%d random number is: \ n", i); scanf ("%f", &a[i]);//enter each person's number
A double for loop is used to design the number of topics and the number of games, and enter numbers;
if (A[i]>100 " Please re-enter The required number " ); I --; // } s =s+a[i]; } g =s/Z; printf ( ", 0.618 *g); // find the golden dot number
Determine whether the input number is legal, if not legal, then I--, and prompt re-entry, the use of s+=s, the calculation of the golden point and agreed to come out;
for (i=1; i<=z;i++) { B[i]=fabs ((0.618*g-a[i])); // find the difference between the number and the golden point, Bin and assign to B[i] printf ("%f\n", B[i]); }
Use the For loop and the Fabs function to assign the difference (all numbers-golden dots) to b[],
for (i=1; i<z;i++) { if(min>b[i]) { min=b[i]; // find the minimum value, bin and identify the ground I personal c=i; } } printf (" The difference between the%f and the minimum, is%d individuals, scored:%d\n", min,c,z);
Use the For loop again to find the minimum value, then find the first value, and print it out to complete the program;
Execute the procedure, the procedure works perfectly, realizes the job arrangement request, if discovers the question, promptly follows up the blog progress, as well as uploads the coding program.
Summary: This procedure can be said is not difficult to write, that is, before oneself has been dragged without a good finish, in the process of the project to constantly improve their programming ability, more note in the team project cooperation and team project personnel get along, again this task, Can reasonably arrange each person's work and play a good job, I feel very important, thank you for this project's small partners and teachers of serious responsibility, a good programming experience!!!
Notes to the Golden Dot game program