C-language Golden dot Game

Source: Internet
Author: User
Tags rounds strcmp

Today in C language to write this, although C is not very familiar, writing or is quite simple, at present also want to write a judge whether the input number is repeated, repeat the need to re-enter, due to time reasons, has not written.

Code:

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h>
The structure of the stored information typedef struct SCORENODE{DOUBLE Score;char name[10];struct scorenode *next;} scorenode,*scorelink;//looking for the nearest and farthest distance from the golden point (not yet considering the same number of inputs) recently added a point to the furthest minus one point void Findm (Scorenode *inlink,scorenode *sclink, Double aver) {Char name[10];//stores the most recent person name Char name1[10];//storage furthest double Temp0,temp1;scorenode *p=null;p=sclink;temp0=temp1= Fabs (Inlink->score-aver); strcpy_s (Name,strlen (inlink->name) +1,inlink->name); strcpy_s (Name,strlen ( Inlink->name) +1,inlink->name) inlink=inlink->next;//printf ("%lf\n", Inlink->score); while (InLink) { Double Temp2=fabs (Inlink->score-aver); if (TEMP0&GT;TEMP2) {temp0=temp2;strcpy_s (Name,strlen (inLink->name) +1 , inlink->name);} if (TEMP1&LT;TEMP2) {temp1=temp2;strcpy_s (Name1,strlen (inlink->name) +1,inlink->name);} Inlink=inlink->next;} while (Sclink) {if (strcmp (name,sclink->name) ==0) {sclink->score=sclink->score+1;} if (strcmp (name1,sclink->name) ==0) {sclink->score=sclink->score-1;} Sclink=sclink->next;} Print output while (p) {printf ("The score for"%s is:%lf\n ",p->Name,p->score);p =p->next;}} void Goldpoint () {int num;int time;double sum=0;double aver;int i;scorenode *head,*p,*q,*head0,*q0,*p0;head=null;head0 =null;q=null;q=head;q0=head0;printf ("Please enter number of participants: \ n"), scanf_s ("%d", &num);p rintf ("Please enter several rounds required: \ n"); scanf_s ("%d", &time);p rintf ("1th round start \ n");
The first round needs to be BAA individual enter their own name and their own number for (i=0;i<num;i++) {p= (Scorenode *) malloc (sizeof (Scorenode));p 0= (Scorenode *) malloc ( sizeof (Scorenode));p rintf ("Please enter your name: \ n"), scanf_s ("%s", P->name,sizeof (p->name));p rintf ("Please enter your score: \ n"); scanf _s ("%lf", &p->score,sizeof (P->score));p 0->next=null;p->next=null;if (head==null) {head=p;q=p;} Else{q->next=p;q=p;} sum+=p->score;
Initialize the linked list strcpy_s (P0->name,strlen (p->name) +1,p->name) that holds the score;p 0->score=0;if (head0==null) {head0=p0;q0= P0;} Else{q0->next=p0;q0=p0;}} aver=sum/num*0.618;printf ("aver=%lf\n", aver); Q=head;q0=head0;findm (q,q0,aver); sum=0;printf ("1th round"); for (i=0; i<time-1;i++) {printf ("Start \%d", (i+2)), Q=head;while (q) {printf ("%s Please enter your score: \ n", q->name); scanf_s ("%lf", &q->score); sum+=q->score;q=q->next;} AVER=SUM/NUM*0.618;Q=HEAD;Q0=HEAD0;FINDM (Q,q0,aver); sum=0;printf ("End of%d rounds \ n", (i+2));} printf ("Game over \");} void Main () {Goldpoint ();}

  

C-language 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.