Thread: what's wrong?

  1. #16
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    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:
    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?
       cout<<"Error, invalid input!"<<endl;
    Sorry, hope we aren't hijacking this thread!
    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..
    No problem, congrats!
    Last edited by PJYelton; 12-27-2004 at 11:53 PM.

  2. #17
    Registered User
    Join Date
    Dec 2004
    Not at all. At first I thought that post was directed towards me and I was beginning to get a little worried until I read on.

  3. #18
    Registered User
    Join Date
    Feb 2002
    int main()
    //right after your string decleration.. do this...
    string choice (" ");
    int first, second;

    and you dont have to use it twice... in if statments.. as first second, and then first1 and second1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM