I'm trying to create a program in which the user can enter a series of player names and scores and read them back. However, I'm having trouble storing their input using getline. On getline in the InputData function, visual studio states, "Error: no instance of overloaded function "getline" matches the argument list argument types are: (std::istream, char)", and on ==, it says, "Error: operand types are incompatible ("char" and "const char *")". Here is my code:
#include <iostream>
#include <string>
using namespace std;
int InputData(string [], int [], int);
void DisplayPlayerData(string [], int [], int);
void main()
{
string playerNames[100];
int scores[100];
int sizeOfArray = sizeof(scores);
int sizeOfEachElement = sizeof(scores[0]);
int numberOfElements = sizeOfArray / sizeOfEachElement;
cout << numberOfElements;
int numberEntered = InputData(playerNames, scores, numberOfElements);
DisplayPlayerData(playerNames, scores, numberOfElements);
cin.ignore();
cin.get();
}
int InputData(string playerNames, int scores[], int size)
{
int index;
for (index = 0; index < size; index++)
{
cout << "Enter Player Name (Q to quit): ";
getline(cin, playerNames[index]);
if (playerNames[index] == "Q")
{
break;
}
cout << "Enter score: ";
cin >> scores[index];
}
return index;
}