Hi,
Had a question about a couple little array feeding programs I've been trying to get working. These were posted on this board (by someone named Mookie??) in answer to another question I asked about arrays.
Code:
// ArrayHelp3.cpp
//having the same problem as ArrayHelp4.cpp
//Output:
// Enter some text: here's my text
//
// Enter some text: Continue? (y/n):
// Enter some text: Continue? (y/n):
// Enter some text: Continue? (y/n):
// etc.
// Something not initialized???
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{ const int MAXSETS = 5;
char txtArray[MAXSETS][81] = {'\0'};
int i = 0;
char choice = 'y';
do
{ cout << "Enter some text: ";
cin.getline(txtArray[++i], MAXSETS, '\n');
cout << "Continue? (y/n): "; cin >> choice;
//choice = (tolower(choice));
cout << endl;
} while(choice == 'y');
if(choice != 'y')
{ for(i=0; i<MAXSETS; i++)
cout << txtArray[i] << endl;
}
system("pause");
return 0;
}
Here's another one with a similar problem if not the same one:
Code:
// ArrayHelp4.cpp
//when it gets to the while loop, it somehow skips the cin.getline
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{ const int MAXSETS = 5;
char Array[MAXSETS][15] = {'\0'};
int count = -1;
char choice = 'y';
for(int j=0; j < MAXSETS && choice == 'y'; j++)
//while(choice == 'y' && count < MAXSETS)
{ cout << "\nEnter some text: ";
cin.getline(Array[++count], 15, '\n');
//cin.ignore();
cout << "\nContinue? (y/n): ";
cin >> choice;
//if(choice != 'y')
}
cout << "\n";
for(int i=0; i<MAXSETS; i++)
cout << "Array[" << i << "] " << Array[i] << "\n";
system("pause");
return 0;
}
Thanks for any help/suggestions you can give.
Swaine777