Project not running?
Dec 14, 2014 at 11:58pm UTC
So I have this code here, and I am struggling to get it to compile, all I get is the error "error C4716: 'getNames' : must return a value"
From what I can see everything should be working. Any ideas?
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
#include <iostream>
#include <string>
using namespace std;
int getNames(string[], int );
void displayNames(string[], int );
int main()
{
int const arraySize(10);
int names = 8;
string array[arraySize];
getNames(array, arraySize);
displayNames(array, 8);
return 0;
}
int getNames(string array[], int arraySize)
{
int names;
for (int count = 0; count < 10; count++)
{
cout << "Enter name " << (count + 1) << " of 8: " ;
cin >> names >> array[count];
if (count < 8)
{
names++;
}
}
cout << names << " received." ;
}
void displayNames(string array[], int names)
{
for (int count = 0; count < names; count++)
{
cout << array[count] << endl;
}
system("PAUSE" );
}
Dec 15, 2014 at 12:07am UTC
From what I can see everything should be working
int getNames(string array[], int arraySize)
Here you
promised that this fuction will return int. It didn't. Behavior of this program is undefined and your IDE did you a favor by detecting it.
Dec 15, 2014 at 12:14am UTC
oh, duh.
so should changing it to void fix it?
Dec 15, 2014 at 12:29am UTC
You cant try and find out.
Dec 15, 2014 at 12:51am UTC
i wasn't at my computer.
i just did and it worked, thank you!
Topic archived. No new replies allowed.