An array of pointers to char is generally better than a two dimensional array. The problem was that you were trying to initialize the array inside the class definition, this doesn't make sense to the compiler so you get errors. Try this instead:
Code:
#include <iostream>
using namespace std;
class help {
public:
static char *info[];
void helpon(int query);
void showmenu();
bool isvalid(int query);
};
char *help::info[]={
"",
"if(condition) statement;",
"switch(expression) { //... };",
"for(init;condition;iteration) { //...};",
"while(condition) { //...};",
"do{ //...} while(condition);",
"break;",
"continue;",
"goto label;"
};
void help::helpon(int query) {
cout<<info[query]<<endl;
return;
}
void help::showmenu() {
cout<<"Help on:"<<endl;
cout<<"1: if"<<endl<<"2: switch"<<endl<<"3: for"<<endl<<"4: while"<<
endl<<"5: do while"<<endl<<"6: break"<<endl<<"7: continue"<<endl<<
"8: goto"<<endl<<"9: functions"<<endl<<"0: quit"<<endl;
}
bool help::isvalid(int query) {
if(query<0||query>9)
return false;
else
return true;
}
int main() {
int query;
help cpp;
for( ; ; ) {
do {
cpp.showmenu();
cin>>query;
} while(!cpp.isvalid(query));
if(!query)
break;
cpp.helpon(query);
}
return 0;
}
-Prelude