One thing I am wondering is how to I put a string of info into a multidimensional array?
Let me specify the array:
Now in one of my functions I need to input between 1 to 10 different names into that array.
I have tried three different ways, each being unsuccessful. Let me show you the ways I have tried. The first being the only one where I have got some result, but I need it to include spaces.
Code:
for (i = 0; i < 10; i++)
{
cin >> name[i];
...
}
Obviously that would only input everything up until a whitespace character.
I tried the following two methods which I though would've worked, but didn't...
Code:
#include <cstring>
...
for (i = 0; i < 10; i++)
{
gets(name[i]);
...
}
Code:
for (i = 0; i < 10; i++)
{
cin.getline(name[i], 80, '\n');
...
}
Here is a snippet of my code and it's output with effort 2.
Code:
void enter()
{
int i;
for (i = 0; i < 10; i++)
{
cout << "\n\nEnter employee's name: ";
gets(name[i]);
cout << "Enter phone number: ";
gets(phone[i]);
cout << "Enter number of hours worked: ";
cin >> hours[i];
cout << "Enter wage: ";
cin >> wage[i];
}
}
Code:
Enter employee's name: Enter phone number:
One more question, what's the difference between gets() and cin.getline() anyhow? Is there a better one to use?
I'm probably just doing something extremely stupid, but I'm still new at this so take it easy on me