The point of the code is to take a word SUBTRACTION or multiplication as an enum and use that to choose which operation is done and then take two numbers and operate. Can someone please tell me why it isn't working?
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
enum Operation
{
OPERATION_SUBTRACTION,
OPERATION_ADDITION, OPERATION_DIVISION,
OPERATION_MULTIPLICATION
};
Operation oMyOperation;
cout << "Which operation would you like to use? " ;
cin >> oMyOperation;
switch (oMyOperation)
{
case OPERATION_SUBTRACTION:
{
int x;
cout << "What is the number you would like to subtract from?"<< endl;
cin >> x;
int y;
cout << " What is the number you would like to subtract?" << endl;
cin >> y;
int difference = x - y;
cout << " The difference is " << difference <<"." << endl;
break;
}
case OPERATION_ADDITION:
{
int x;
cout << "What is the first number you would like to add?"<< endl;
cin >> x;
int y;
cout << " What is the second number you would like to add?" << endl;
cin >> y;
int sum = x + y;
cout << " The sum is " << sum <<"." << endl;
break;
}
case OPERATION_DIVISION:
{
int x;
cout << "What is the dividend?"<< endl;
cin >>x ;
int y;
cout << " What is the divisor??" << endl;
cin >> y;
int quotient = x/y ;
cout << "The quotient is " << quotient << "." << endl;
break;
}
case OPERATION_MULTIPLICATION:
{
int x;
cout << "What is the first number you want to multiply?" << endl;
cin >> x ;
int y;
cout << "What is the second number you wish to multiply?" << endl;
cin >> y ;
int product;
product = x * y;
cout << " The product is " << product << "." << endl;
break;
}
default:
{
cout << "Try again";
break;
}
}
return 0;
}
I wanted to do something like this :
void PrintColor(Colors eColor)
{
using namespace std;
switch (eColor)
{
case COLOR_BLACK:
cout << "Black";
break;
case COLOR_WHITE:
cout << "White";
break;
case COLOR_RED:
cout << "Red";
break;
case COLOR_GREEN:
cout << "Green";
break;
case COLOR_BLUE:
cout << "Blue";
break;
default:
cout << "Unknown";
break;
}
}
Instead of printing the color, I wanted to use the input to choose which operation to use.