标签:min std stdio.h 输入 tor for include c语言 开始
领航员:干友恒 驾驶员:曹纪涛
我们用的语言是C语言,用的编程环境是Visual C++ 6.0,我们限定输入的数字是0-100之间的有理数,提供一个菜单给用户选择,玩家的人数和游戏的次数都由用户来输入,再将玩家输入的数字算出黄金点,再和玩家输入的数字进行比较,最后输出玩家的得分,由得分可以看出谁是胜利者。
GITHUB:https://github.com/GYH1205392387/MY-REPOSITORY/blob/master/%E7%BB%93%E5%AF%B9%E9%A1%B9%E7%9B%AE%EF%BC%9A%E9%BB%84%E9%87%91%E7%82%B9%E6%B8%B8%E6%88%8F
代码如下:
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
struct
{
float data;
float grade;
}Player[100];
void game();
void main()
{
int n;
printf("--------------黄金点游戏------------\n");
printf("\n规则:输入的数仅为0~100之间的有理数\n\n");
printf("--------------1.开始游戏------------\n");
printf("--------------2.退出游戏------------\n");
printf("------------请输入您的选择:--------\n");
scanf("%d", &n);
system("cls");
if (n == 1)
{
game();
}
else
exit;
}
void game()
{
int N, a, b, c, i, j, k;
printf("请输入游戏人数:");
scanf("%d", &N);
printf("\n请输入游戏次数:");
scanf("%d", &a);
for (i= 0; i < N; i++)
{
Player[i].grade = 0;
}
for (j = 1; j <= a; j++)
{
int num = 0, max = 100, min = 0;
float G=0,m=0;
printf("\n第%d次游戏:\n",j);
for (i = 0; i < N; i++)
{
loop: printf("玩家%d输入的数为:",i+1);
scanf("%f", &Player[i].data);
if(Player[i].data>=0&&Player[i].data<=100)
{
num += Player[i].data;
}
else
{
printf("输入的数据有误,请重新输入!\n");
goto loop;
}
}
G = (float)num*0.618 / N;
printf("\n黄金G点值为:%f\n\n",G);
for (k = 0; k < N; k++)
{
m = abs((float)Player[k].data - G);
if (m>=min)
{
min = m;
b = k;
}
if (m <= max)
{
max = m;
c = k;
}
}
Player[b].grade += -2;
Player[c].grade += 2;
for (i = 0; i < N; i++)
{
printf("玩家%d的得分为:", i+1);
printf("%f\n", Player[i].grade);
}
}
}
标签:min std stdio.h 输入 tor for include c语言 开始
原文地址:http://www.cnblogs.com/GGGGGGG/p/7645636.html