0

instructions for code

I am getting errors that say "no match for operator and things having to do with my_operation. Why am I getting errors for this? I am not sure why I added a boolean when it's not even correct.

#include <iostream>
using namespace std;

int main() {
    enum Operation {Multiply = 'M', Add = 'A', Difference = 'D'};
    int result;
    int num1, num2;
    Operation my_operation;
    char choice;
    bool = true;
    cout<<"Enter two integers:"; cin>>num1>>num2;

    do
    {
        cout<<"Choose from the list of operations:"<<endl;
        cout<<"M / Multiply"<<endl;
        cout<<"A / Add"<<endl;
        cout<<"D / Difference"<<endl;
        cin>>my_operation;

            switch (my_operation){
                case M:
                    result = num1 * num2;
                    break;
                case A:
                    result = num1 + num2;
                    break;
                case D:
                    result = num1 - num2;
                    break;
                default:
                    cout<<"Try again. Please choose to Multiply, Add, or to find the Difference.";
                    break;
            }
    } while (true);
    cout<<"The result of the operation is "<<result<<endl;

    return 0;
}
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • I think you need to take a deep breath and spend some time with a [good book](https://stackoverflow.com/q/388242/631266). For instance `cin>>my_operation;` is attempting to use a function that doesn't exist and you haven't written. ( A particular overload of operator>>( ) ) – Avi Berger Oct 04 '22 at 04:50
  • Don't tell us what error messages say. Instead, [show them completely](https://meta.stackoverflow.com/questions/359146), by copying and pasting, and formatting them like code. Also, do not use an image from your homework to explain what the code needs to do. Instead, explain the requirements in your own words. Make sure to ask a *specific* question, which starts with isolating the part that causes a problem, and explaining what *that part* needs to do - see [mre]. – Karl Knechtel Oct 04 '22 at 06:14
  • Where the code says, for example, `case M:`, what do you expect this to mean? *Why*? (Hint: is `M` the same thing as `'M'`? Is `M` the same thing as `Multiply`?) – Karl Knechtel Oct 04 '22 at 06:17

1 Answers1

-1

Check if this is what wanted to do

#include <iostream>
using namespace std;

int main() {
    enum Operation {Multiply = 'M', Add = 'A', Difference = 'D'};
    int result;
    int num1, num2;
    Operation my_operation;
    char choice;
    // bool = true;
    cout<<"Enter two integers:"; cin>>num1>>num2;

    do
    {
        cout<<"Choose from the list of operations:"<<endl;
        cout<<"M / Multiply"<<endl;
        cout<<"A / Add"<<endl;
        cout<<"D / Difference"<<endl;
        cin>>choice;

            switch (choice){
                case Multiply:
                    result = num1 * num2;
                    cout<<"The result of the operation is "<<result<<endl;
                    break;
                case Add:
                    result = num1 + num2;
                    cout<<"The result of the operation is "<<result<<endl;
                    break;
                case Difference:
                    result = num1 - num2;
                    cout<<"The result of the operation is "<<result<<endl;
                    break;
                default:
                    cout<<"Try again. Please choose to Multiply, Add, or to find the Difference.";
                    break;
            }
    } while (true);
    

    return 0;
}

You have some unnecessary things in your code. I haven't changed those. I have tried to do minimum modification to make your code working.

saurav
  • 16
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 08 '22 at 00:26