I am having issues getting this working. This is a simple program that is designed to ask a user if he would like to enter a string, if yes, the user is prompted to enter it and its stored in a char array. User is then asked if he wants to enter another string... Once user responds no, the program outputs the strings and the program ends... Note: I'm using in.getline(myarray[i], MAX, '\n'), to avoid white space problems if user enters a space. Lastly I would like the option of letting user enter any number of strings, but how would you do this when declaring the 2 dimentional char array?
#include <iostream>
#include <string>
usingnamespace std;
constint MAX = 81; //max char is sting is 80
int main(){
string y_n;
bool go = true;
char myarray [][MAX]; //How can i make this allow an open ended amount of string entries?
int inputcount = 0;
cout << "Do you want to input a Phrase? ('Yes' or 'No')" ;
cin >> y_n;
do{
if((y_n == "no") || (y_n == "No"))
go = false;
elseif (y_n == "yes" || y_n == "Yes")
for(int i=0; i <= 4; i++)
{
cout << "Please Enter the Phrase:";
cin.getline(myarray[i], MAX, '\n');
++inputcount;
cout << "Do you want to input a value (Y or N)" ;
cin >> y_n;
}
else{
cout << "Please enter a valid response (Either 'Yes' or 'No'" ;
cin >> y_n;
}
}while (go);
for(int z = 0; z < inputcount; z++)
cout << "Entry # " << z << " equals : " << myarray[z] << endl;
return 0;
}