C++ Switch Statement
11:15 23 Nov 2013

Recently (yesterday hah) I started learning C++. I am trying to make a simple calculator to practice. I used a switch statement in order to call upon the correct method(or is it function.. don't know the nuances of c++...) within the class;

However, the code will not compile because I am using a string to define which case to use and also defining multiple classes to have the same result.

Here is the switch statement (I've only done addition to squash any bugs before I add the others):

switch(input){
        case 'A': case 'a': case 'add': case 'Add':
            cout << bo.addNum();
            break;
        default:
            cout << "Not addition";
            break;
    }

The error I'm getting is the following:

basic.cpp:41:2: error: statement requires expression of integer type ('string'
      (aka 'basic_string, allocator >') invalid)
        switch(input){
        ^      ~~~~~
basic.cpp:42:28: warning: multi-character character constant [-Wmultichar]
                case 'A': case 'a': case 'add': case 'Add':
                                         ^
basic.cpp:42:40: warning: multi-character character constant [-Wmultichar]
                case 'A': case 'a': case 'add': case 'Add':
                                                     ^

Here is the code in its totality:

#include 
#include 
#include 

using namespace std;

class beckahClass{
public:
    void setNum(int num1, int num2){
        a = num1;
        b = num2;
    }
    int addNum(){
        return a + b;
    }
    int subNum(){
        return a - b;
    }
    int divNum(){
        return a / b;
    }
    int multNum(){
        return a * b;
    }
private:
    int a, b;
};

int main (void){
    beckahClass bo;
    string input;
    int a, b;

    cout << "Please specify the operation to preform by the following:\n A: add\nS: subtract\nM: Multiple\nD: divide\nEnter operation:  ";
    cin >> input;

    cout << "Enter the two nums you want to preform your operation on: ";
    cin >> a >> b;
    bo.setNum(a, b);

    switch(input){
        case 'A': case 'a': case 'add': case 'Add':
            cout << bo.addNum();
            break;
        default:
            cout << "Not addition";
            break;
    }   
    return 0;
}

I also realize there are probably more efficient ways to use logic; because I'm just starting C++, I would greatly appreciate any critique. I had been looking up 'maps' before briefly and was wondering if this might be a good instance to use it in?

Thanks.

c++ switch-statement