Calculator

whats wrong with this
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
//catchOS 1.0001 full adding, subtracting
//multiplying and dividing calculator

#include <iostream>
#include <stream>

int main ()
{
string plusminus
int a, b, result
result = a + b ;
cout << " Welcome to catchOS 1.0001 " << endl ;
cout << " This version is able to add, minus, times and divide " << endl ;
cout << " Which kind of sum would you like to do: " ;
getline (cin, plusminus);
cout << " What is the first number in your " << plusminus << " sum " ;
cin >> a;
cout << " What is the second number in your " << plusminus << " sum " ;
cin >> b;
if (plusminus == "add")
 a + b = result;
else if (plusminus == "minus")
 a - b = result;
else if (plusminus == "divide")
 a / b = result;
else if (plusminus == "times")
 a * b = result;
else
 cout <<
" the program does not understand your statement, " << endl <<
" please remember to use the statements 'add' , 'minus' " << endl <<
" 'times' and 'divide' ";
cout << " The answer of " << a << plusminus << b << " = " << result;
return 0;
}
Last edited on
The if else part is completely wrong:
1
2
if (plusminus = add)
 a + b = result;

operator = is for assignment, not for comparison
add is not declared in your program, if you want a string use double quotes
operator = assigns the value of the right operand to the left operand

what the above should be:
1
2
if (plusminus == "add")
    result = a + b;


the same applies to the elses


If you want to learn C++ I suggest you the tutorials: http://www.cplusplus.com/doc/tutorial/
Topic archived. No new replies allowed.