Ok, I see that part, but what I'm confused about is when you say it executes the code. I'm just curious how your code figures out what code to execute without more if/switch statements. For example with the calculator:
Sorry, hope we aren't hijacking this thread!Code:void add();
void subtract();
void divide();
void multiply();
void execute(string s)
{
string acceptable[4]={"add", "subtract", "divide", "multiply"};
for (int x=0; x<4; x++)
{
if (!strcmp(s, acceptable[x]))
{
// this is where I am confused, how do you avoid using if or switch statements
// here to call the appropriate function?
return;
}
}
cout<<"Error, invalid input!"<<endl;
}
No problem, congrats!Quote:
I just remade the calculator with the switch statement. It went smoothly except for the string choice; I had declared. A message came up saying that switch declares quantity not an integer. So I just changed the string choice; to int choice; and it compiled fine. Thanks again..