Help with code

I don't know why is program is doing an infinite loop. After I enter the number of students it keeps asking for more students beyond the number I specified. Also i need to bubble sort the students names with the corresponding score and I don't know where to begin. Then calculate average of the scores and display it.

This is my code so far:

#include <cstdlib>
#include <iostream>


using namespace std;

void testSize(int); // validates user input for size
void getData(int size, int [], char [][6]);


int main(int argc, char *argv[])
{
int Scores[5];
char Students [5][6];
int size;

cout << "Enter number of students: ";

testSize(size);

getData(size,Scores,Students);


system("PAUSE");
return EXIT_SUCCESS;
}
void getData(int size, int testScore[],char studentName[][6])
{

int count;

for (count = 0; count <= size; count++)
{
cout << "Enter" << " student name " << (count +1)
<< ": ";
cin >> studentName[count];
}

for (count = 0; count <= size; count++){
cout << "Enter test score for " << studentName[count]
<< ": ";
cin >> testScore[count];
cout << endl;

while (0 > testScore[count] || testScore[count] > 100)
{
cout << "Re-enter test score for " << studentName[count]
<< ": ";
cin >> testScore[count];
}
}

}
void testSize(int size)
{
while(!(cin >> size))
{
cout << "Please enter a number! \n";
cin.clear(); // clear error condition
cin.sync(); // clear input stream
cout << "Enter number of students: ";
}

while(size < 0)
{
cout << "YOU CANNOT ENTER A NEGATIVE NUMBER!\n";
cout << "Please enter Number again: ";
cin >> size;
}
}
Function void testSize(int size) needs to pass the parameter by reference, using the & operator.
http://www.cplusplus.com/doc/tutorial/functions2/
Last edited on
Thanks it doesn't keep going but how can i validate the users input when they have to put the students name. So that they can't put a number or a single character.
Topic archived. No new replies allowed.