学习如何在C中使用数组 [英] Learning how to use array in C

查看:71
本文介绍了学习如何在C中使用数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个问题应该是这样的:



球队:A / B

球员编号:1-12

积分:



优胜者是A / B队

来自团队的游戏编号%d的玩家A.

来自B队的游戏编号%d的玩家。



So I have this problem where it should look like this:

Team: A/B
Player No: 1-12
Points:

Winner is Team A/B
Player of the Game No.%d from Team A.
Player of the Game No.%d from Team B.

#include <stdio.h>


int
main (void)
{
	char team, another;
	int teamA[12], teamB[12], pointA=0, pointB=0, NoA=0, NoB=0, points;
	int potgA=0, potgB=0;
	
		do {
			printf("Team :");
			scanf(" %c", &team);
			switch (team)
			{
				case 'a':
				case 'A':
					printf("\nPlayer No. :");
					scanf("%d", &teamA[NoA]);
					printf("\nPoints :");
					scanf("%d", &points);
					pointA = pointA + points;
					if(points>potgA)
					{
						points = teamA[NoA];
						potgA = teamA[NoA];
					}
					break;
				case 'b':
				case 'B':
					printf("\nPlayer No. :");
					scanf("%d", &teamB[NoB]);
					printf("\nPoints :");
					scanf("%d", &points);
					pointB = pointB + points;
					if(points>potgB)
					{
						points = teamB[NoB];
						potgB = teamB[NoB];
					}
					break;
			}
			printf("\nAnother Player? :");
			scanf(" %c", &another);
		}
		while(another == 'y' || another == 'Y');
		
		if(pointA == pointB)
			printf("\nDraw");
		else if(pointA > pointB)
			printf("\nWinnder is Team A");
		else
			{
			printf("\nWinner is Team B");
			}
		printf("\nPlayer of the Game No.%d from Team A", potgA);
		printf("\nPlayer of the Game No.%d from Team B", potgB);
		
}





现在我遇到的问题是我无法获得该播放器的播放器游戏工作正常。



我尝试过:



我没有真正尝试过多,因为我无法弄清楚什么是错的,但我认为这是两种情况的IF部分。

我错过了另一个变量吗? />
我无法编码这个想法。

如果(玩家编号的点数是>团队中最大的点数)

potgA =玩家编号



now the problem that I'm having is I can't get the Player of the Game to work properly.

What I have tried:

I haven't really tried as much because I can't really figure out what's wrong but I think that it is something in the "IF" section of both cases.
Am I missing another variable?
I can't code this thought.
If (player number's point is > the largest point on the team)
potgA = Player number

推荐答案

简单:你正在记录他们得分但不是他们是谁。

Simple: you are recording the points they scored, but not who they are.
if(points>potgB)
{
    points = teamB[NoB];
    potgB = teamB[NoB];
}

告诉你最高分,是的。但是你没有在任何地方录制NoB(或NoA),所以你后来不知道它是哪个播放器。

我会这样做而不是存储 points potG 但是播放器 - NoB值 - 而不是。因为您可以随时使用它来访问玩家点信息。

Tells you the highest points, yes. But you don't record NoB (or NoA) anywhere, so you have no idea later which player it was.
The way I would do it it not to store points or potG but player - the NoB value - instead. Because you can use that at any time to access the player point information.


这篇关于学习如何在C中使用数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆