Simple Calculator Problem

Feb 26, 2013 at 10:51pm
Here is the code for my simple calculator:
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
#include <iostream>

using namespace std;

float a;
float b;
char c;
float d;


int main() {
cout<<" Calculator \n Enter your equation with each action being followed by enter\n";
cin>> a;
cin>> c;
cin>> b;
switch (c) {
case '+':
         d == a + b;
         cout<<"=\n" <<d<< endl;
         break;
case '-':
         d == a - b;
         cout<<"=\n" <<d<< endl;
         break;
case '*':
         d == a * b;
         cout<<"=\n" <<d<< endl;
         break;
case '/':
         d == a / b;

         cout<<"=\n"<< "" << d << endl;
         break;
default:
        cout<<"Invalid\n Try Again";

}

}

The output works great except no matter what numbers / operations I input it always comes out with 0 I know that it is reaching the cout that displays the output because the = is displayed but it always says 0. Any help would be appreciated.
Thanks!
Feb 26, 2013 at 11:16pm
You have not used the assignment operator for each case of your switch, you've used the equals too. Change == to = in lines 18, 22, 26, and 30
Feb 26, 2013 at 11:17pm
worked great thanks so much for your help
Topic archived. No new replies allowed.