Calculator code.

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <cstdlib>
using namespace 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;
} 
you cant read a string into your enum (line 19).
I guess you'll need to read in a string first with getline maybe:
http://www.cplusplus.com/doc/tutorial/basic_io/

But using this string to determine the operation kinda makes your enum redundant.
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.
Topic archived. No new replies allowed.