xiansen 0 Newbie Poster

Hi guys, below is what i have so far and I am having trouble outputting the players' data in descending order. For some reason, my output is in ascending order. Also, I need to check if the user enters a player number that has already been used, and then prompt the user for another number. One more thing, that is to check if two players have the same name then ask the user if this is correct, and provide a way to re-enter the most recent name if it is not correct.I have tried everything I can on my own and met a dead end. Any kind of help is really appreciated!

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;
const int SIZE = 50;

struct Players
{	
	// player's first name and last name.
	char Firstname[SIZE], Lastname[SIZE];        
	int playNum; // Number of players            
	int Points;  // Scores of players
};
int main()
{
	int NUM_PLAYERS;
	
	//gets the total number of players
	cout << "how many players do you want to keep track of?";
	cin >> NUM_PLAYERS;

	//Array of structures
	Players *players = new Players[NUM_PLAYERS];      
    int index;                 //Loop

	// gets the player's first name, last name,
	//number and career scores.
    
    for (index = 0; index < NUM_PLAYERS; index++)
    {
        cout << "Please enter player " << index+1;
		cout << " first name: ";

		
		
        cin.ignore();
		cin.getline( players[index].Firstname, SIZE );
		cout << endl;
		
		cout<< "Please enter player " << index+1;
		cout << " last name: ";
		
		
		cin.getline(players[index].Lastname, SIZE);

		cout << endl;
		//Need Help comparing players' names
		// if 2 names are the same, verify with the user and 
		// offer a way to correct it.

		/*

		if ((players[0].Firstname==players[index].Firstname)
			&&(players[0].Lastname==players[index].Lastname))
		{
			cout << "is this the correct name?";
		}
		*/
		



        cout << "Please enter players "; 
		cout << index+1 << " number: ";

        cin >> players[index].playNum ;
		cout << endl;

		//Please help me with this too.
		//if the user enter the same number for different players
		//prompts the user to enter a different one.

		/*
		while(players[0].playNum==players[index].playNum)
		{
			cout << "please enter a different number.";
			cout << endl;
			
		}
		*/

		

        cout << "Please enter player ";
		cout << index+1 << " career scores: ";

        cin >> players[index].Points ;
		cout << endl;

    } 


	// showing the data of player
	//who has the biggest carrer score
	int Largest;

	Largest = players[0].Points;
	for(index = 0; index < NUM_PLAYERS ;index++)
	{
		if(players[index].Points > Largest)
		{Largest =players[index].Points;
		Largest=index;
		}
	}

	cout << "the top scorer is " << players[Largest].Firstname;
	cout << " " << players[Largest].Lastname << ", ";
	cout << "#" << players[Largest].playNum << " with ";
	cout << players[Largest].Points <<  " points.";
	

	//I don't know what's wrong with my sorting.
	// it's in ascending order..
	// the program is supposed to output in descending order.
	int temp; // temporary swap variable

	for(int i = 0; i < NUM_PLAYERS; i++)
        {
                for(int j = 0;j < NUM_PLAYERS - 1; j++)
                {
                        if(players[j].playNum > players[j+1].playNum)
                        {
                                
							temp = players[j].playNum;
							players[j].playNum = players[j+1].playNum;
                                players[j+1].playNum = temp;
								
                        }
                }
        }     

	for( int i = 0; i < NUM_PLAYERS; i++)
	{
		cout << players[i].Firstname << ",";
		cout << players[i].Lastname;
		cout << "#" << players[i].playNum;
		cout << players[i].Points;
	}
	

	// Delete the memory.
	delete [] players;




	system("pause");

    return 0;
	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.