Need Help With Code About Structures

Hey, I'm having some trouble with my code. I had to rewrite my original code using structures. I've changed some things but it will not run after inputing the first name. Please point out what is wrong with my code. Thanks in advance. I can not change the parameters in the functions.



#include <iostream>
#include<string>
using namespace std;

struct highscore
{
	int score;
	char name;
};

void initializeData(highscore scores[],int size);
void sortData(highscore scores[],int size);
void showData(highscore scores[],int size);

int main()
{
	int size;
	int *data = new int[1000];
	string *name = new string[1000];
	cout << "How many scores will you enter?: ";
	cin >> size;
	highscore *scores = new highscore[size];
	initializeData(scores, size);
	sortData (scores, size);
	showData (scores, size);
	delete [] data;
	delete [] name;
	name = 0;
	data = 0;
	return 0;
}

void initializeData (highscore scores[], int size)
{
	for (int i = 0; i < size; i++)
	{
		cout << "Enter the name for score # " << (i +1) << ": ";
		cin >> scores[i].name;
		cout << "Enter the score for score # " << (i+1) << ": ";
		cin >> scores[i].score;
	}
}

void sortData (highscore scores[], int size)
{
	bool swap;
	int temp;
	do
	{
		swap = false;
		for (int count = 0; count < (size +1); count++)
		{
			if (scores[count].score < scores[count + 1].score)
			{
				temp = scores[count].score;
				scores[count].score = scores[count + 1].score;
				scores[count + 1].score = temp;
				swap = true;
			}
		}
	} while (swap);
}
void showData (highscore scores[], int size)
{
	cout << "Top Score" << endl;
	for (int count = 0; count < size; count ++)
		{
		cout << scores[count].name<< " :";
		cout << scores[count].score << " ";
	    cout << endl;
		}
}
char name; Should be std::string name;
Thanks MiiNiPaa, that fixed the error. But is there a way to keep
char name;
in the structure and use it. Because that is one of the requirements my professor asked us to do.
char is a name implied is a single character. You can use:
a) char* name; But you should use dynamic memory allocation and/or constructors to properly use it.
b) char name[something]; Have limited size, takes excess memory and just aren't suited for C++.
Topic archived. No new replies allowed.