I have this program it allows the users to enter a name and a score it saves all the names to one array and all the scores to another. The program then displays all the names and scores in a list.
I want to have the code for displaying the the list of names and scores be in a separate function. The code works in the int main() function but as soon as i put it in a separate function the code no longer works
here is my code i would just like to know what i need to do to make the list work in the displayfunctiion() instead of the int main () function
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
double DisplayArrays(string studentName, int score)
{
studentName[20];
score[20]
cout << "Name " << "Score" << endl;
cout << "=============================" << endl;
for (int n = 0; n < 20; n++)
{
if (studentName[n] == "stop"|| score[n] == -1)
{
break;
}
cout << studentName[n] << " " << score[n] << endl;
}
}
int main()
{
const int ARRAYTIME = 20;
string studentNames[ARRAYTIME];
int scores[ARRAYTIME];
cout << "To end the loop enter 'stop' as student name and '-1' as score" << endl;
for (int i = 0; i < ARRAYTIME ; i++)
{
cout << "Enter student name: ";
cin >> studentNames[i];
cout << "Enter score: ";
cin >> scores[i];
cout << endl;
if (studentNames[i] == "stop" || scores[1] == -1)
{
break;
}
}
cout << endl;
DisplayArrays(studentNames[], scores[]);
/***cout << "Name " << "Score" << endl;
cout << "=============================" << endl;
for (int n = 0; n < ARRAYTIME; n++)
{
if (studentNames[n] == "stop"|| scores[n] == -1)
{
break;
}
cout << studentNames[n] << " " << scores[n] << endl;
}
*********/
return 0;
}
Thanks for you help