what's wrong?

This is a discussion on what's wrong? within the C++ Programming forums, part of the General Programming Boards category; Ok, I see that part, but what I'm confused about is when you say it executes the code. I'm just ...

  1. #16
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    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:
    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;
    }
    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 10:53 PM.

  2. #17
    Registered User
    Join Date
    Dec 2004
    Posts
    31
    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
    Posts
    13
    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
    Ok...

Page 2 of 2 FirstFirst 12
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 Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09: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 Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21