simple array, program crashes **HELP**

The program will ask the user to enter the class code, name, section, and the names of each of the students in the class. Then the list will appear in the output.




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



void printArray (string[], int);




int main ()

{

string cname, ccode, csec, name1, name2, name3, name4, name5, name6, name7, name8, name9, name10,
name11, name12, name13, name14, name15;


cout << "To create a class list please enter the class name, code and section\nDo not use symbols, only letters & numbers\nList only supports up to 15 students\n\n";

cout << "Please enter class name: ";
cin >> cname;

cout << "\nPlease enter class code: ";
cin >> csec;

cout << "\nPlease enter class section: \n\n";
cin >> ccode;


printArray (list, 15);
string list[15];

list[0] = name1;
list[1] = name2;
list[2] = name3;
list[3] = name4;
list[4] = name5;
list[5] = name6;
list[6] = name7;
list[7] = name8;
list[8] = name9;
list[9] = name10;
list[10] = name11;
list[11] = name12;
list[12] = name13;
list[13] = name14;
list[14] = name15;





cout <<"Class name:"<<cname<<" "<<"Class code:"<<ccode<<" "<<"Class section:"<<csec;

cout << list[0] << endl
<< list[1] << endl
<< list[2] << endl
<< list[3] << endl
<< list[4] << endl
<< list[5] << endl
<< list[6] << endl
<< list[7] << endl
<< list[8] << endl
<< list[9] << endl
<< list[10] << endl
<< list[11] << endl
<< list[12] << endl
<< list[13] << endl
<< list[14] << endl;


return 0;
}


void printArray (string list[],int size)
{


for (int x=0 ; x<=size ; x++ )
{

cout << "Enter student's name: ";
cin >> list[x];

}


}
it crashes when name #16 is entered....it should not eaven ask for a 16th name, just 15....this is my first time crating arrays & functions at the same time.
Topic archived. No new replies allowed.