Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
		
}


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
Posted
Updated 11-Oct-17 1:17am

1 solution

Simple: you are recording the points they scored, but not who they are.
if(points>potgB)
{
    points = teamB[NoB];
    potgB = teamB[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.
 
Share this answer
 
Comments
Member 13396113 11-Oct-17 7:33am    
I honestly can't figure it out completely.
Now I'm thinking I need a loop for the storing player no. into the array slot.
don't i need another variable just to store highest point?
if(points > highest point)
potg = noB

OriginalGriff 11-Oct-17 7:46am    
Why would you need another loop? You have a loop for finding the highest points, yes?
And since the points come from an array which you access via a player number, if you store the player number you can access his points at any time later but looking in the array at that player number.
You can use a separate variable to store the "current highest points" just as you are now, but that's just an in-loop shortcut. The highest points comes from the points array[number of the player who scored it] into your points variable anyway!
Member 13396113 11-Oct-17 8:12am    
I'm really sorry if I'm being a pain because this whole thing is so confusing to me.

Would it be okay to have an array for player numbers and another array for the points, that way i can do a loop where it finds the highest point?
OriginalGriff 11-Oct-17 8:24am    
Well...yes. But why would you need one?
You have an array of points-by-player-number (you call it teamA and teamB) and the player number indexes into that to return the points scored by that player.
So if you store the player number that scored the highest points in a variable called hiPlayerA and hiPlayerB (by saying hiPlayerA = NoA;) you can access the actual points value via teamA:
teamA[hiPlayerA]

See what I mean?
Member 13396113 11-Oct-17 8:24am    
So I did this and it worked for me. Was just wondering if you could double check if it's solid or not. Again I apologize for being a noob. Lol
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

int
main (void)
{
	char team, another;
	int teamA[12], teamB[12], pointA=0, pointB=0, NoA, NoB, hipointA=0, hipointB=0;
	int potgA=0, potgB=0;
	
		do {
			printf("Team :");
			scanf(" %c", &team);
			switch (team)
			{
				case 'a':
				case 'A':
					printf("\nPlayer No. :");
					scanf("%d", &NoA);
					printf("\nPoints :");
					scanf("%d", &teamA[NoA]);
					pointA = pointA + teamA[NoA];
					if(teamA[NoA] > hipointA)
						potgA = NoA;
						hipointA = teamA[NoA];
					break;
				case 'b':
				case 'B':
					printf("\nPlayer No. :");
					scanf("%d", &NoB);
					printf("\nPoints :");
					scanf("%d", &teamB[NoB]);
					pointB = pointB + teamB[NoB];
					if(teamB[NoB] > hipointB)
					{
						potgB = NoB;
						hipointB = 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);
		
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900