Hi there! I have neared finishing my program but every time it outputs all the names, I get an error 'a.exe has stopped working'. Can someone tell me what exactly I am doing wrong? I have looked at all the tutorials but I still can't figure it out. Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//function 2 prototype
string secondFunction(string array[], int SIZE);
//function 3 prototype
string thirdFunction(string array[], int NAMES);
int main()
{
//create a string array with room for 10 elements
const int size(10);
string array[size];
int names;
//call the second function passing it the array as
//the first argument and the size of the array
//as the second argument
secondFunction(array, size);
//main should call a third function passing it the array
//as the first argument and the value returned by
//function 2 as the second argument
thirdFunction(array, names);
return 0;
}
//second function should get 8 names from the user
//and return the number of names to main
string secondFunction(string array[], int size)
{
for ( size = 0; size < 8; size++)
{
cout << "Please enter a name: ";
cin >> array[size];
}
return array[size];
}
//third function should display the names from the
//array on separate lines on the computer screen.
string thirdFunction(string array[], int names)
{
for (names = 0; names < 8; names++)
{
cout << array[names] << endl;
}
}
|
My output is as follows:
Please enter a name: adam
Please enter a name: bart
Please enter a name: celia
Please enter a name: dave
Please enter a name: elvis
Please enter a name: frodo
Please enter a name: gimli
Please enter a name: harry
adam
bart
celia
dave
elvis
frodo
gimli
harry
However right after everything outputs, I get a windows crash error Window right over my screen.
Thanks for the help!