here what I got and I keep getting a error because of the "string names[];"

these were my guide lines and I'm getting confused

//declare an array of datatype string
//call it names[]

//declare a function dataEntry that takes a string array as input

void dataEntry(string arr[]);

//implement the function: let the user enter names

//declare a function print that takes a string array as input

void print(string arr[]);

//implement the function; use a for loop to print arr[]

//call your function in main() tp print the array


thanks for helping me out

#include <iostream>
#include <string>

using namespace std;
void dataEntry(string arr[]);
void print(string arr[]);
string x;
int main()
    string names[];
   int blank;
   cin >>blank; 
  return 0;
void dataEntry(string arr[])
     cout<< "Please enter a name"
void print(string arr[])

line 11: when declaring the array you have to tell it how many items the array will contain. For example, if you want the array to contain not more than 10 names then declare it like this:

string names[10];

Declaring dynamic arrays is also possible, but apparently your class is not yet at that level, so I'll just ignore that possiblility for now.

lines 12 thru 15: not needed in function main(). The instructions you posted say nothing about doing that. You do need to add a loop in function print() to display each of the names.

Suggestion: don't attempt to do all the instructions at one time. Instead, code and test them one instruction at a time so that you don't get so confused.

Member Avatar for xander85

In the dataEntry() method after the cin >> there is no variable to store the users input!!! don't you see that?!?!? :O

Member Avatar for xander85

lol, in main wth is for { }

there is no condition...

for(int i = 0, i < //?//, i++)

Have you been studying???

Your code is some way short of a working solution.
I don't think you need a for loop in the main function, probably
a loop is needed in the data entry function. It is not clear whether
there is a set number of names to be entered or if the array is to be created dynamically as suggested in a previous post. If so then a while loop may be needed here eg
while (More)
cout << "Enter next name: ";
cin >> InString;

I haven't put anything into cin because I don't know what to do. What would the InString stand for?
I'm really getting lost, when making the loop to have the user put in the 10 names, you would do something like
for (int i=0; i<11; i++)
but what would be the cin; what it be another string (string x;) and how would you get it inside the array? Every thing I have tried enter doesn't work or just brings up a blank screen that doesnt loop. any help?

how does it a sign the the names down the list inside the array.
My bigest problem is that the book doesn't give many ex and well most of them are just cout and not cout/cin.

Member Avatar for xander85

omg what school you going to?

inString would be a varible that you would declare somewhere b4 you use it in the:
cin>> inString //statement


string inString; //Now memory is allocated for the user to input a string of characters, not including spaces, (you'll learn how to handle white spaces later, with a simple function)....

//Now you can use the memory to store the users input...


cin >> inString;

Member Avatar for xander85

You say the book has no example? What book you have???

I don't care for rudeness, if you would be so kind not to post in this thread again I would appreciate it

>>I'm really getting lost, when making the loop to have the user put in the 10 names, you would do something like
for (int i=0; i<11; i++)

Not quite. Use your fingers to count starting at, and including, zero and going through, and including 10. How many numbers did you count?
How many names do you want to store? What could the syntax be to get that number of names?

>>but what would be the cin;

If you declare arr like this:

string arr[10];

Then arr can hold up to 10 strings. Each string in arr is accessable by using the array name followed by the [] operator with an index inside the []s. The indexes indicate how many strings from the first string do you need to go to find the desired string. So if the index is zero, you want the first string. If the index is 1 you want one string beyond the first one, or the second string in the array. If the index is 5 then you wan the fifth string from the first, or the sixth string in the array.

Each string in arr is therefore known as


where x is the index.

You can display arr[x] using cout and you can assign a value to arr[x] using any valid techique; such as cin >>, the assignment operator, etc. In other words, arr[x] is a string, as long as x is a valid index. Valid indexes will be from zero to size (or capacity depending on your syntax) of the array minus 1. So if arr has size 10 then valid indexes will be from zero to 9.

Are you still suffering with your array problem? Have you tried this for your data input?

for(int i = 0;i < 5;i++)
cout << "Enter name: ";
cin >> myArray;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.