0

can someone tell me why this doesn't work? (i'm trying to create a simple calculator)

#include <iostream> using namespace std; int main() { int a; int b; int a+b; cout << "Enter a value \n"; cin >> a; cout << "enter second value \n"; cin >> b; cout << a+b; return 0; }

27th Dec 2018, 11:42 PM
Botta
 Botta - avatar
2 Answers
+ 4
int a+b; Just erase that and it works! The line doesn't make sense. You are preparing two containers, a and b, for your two operands. Those get filled later. That should be all. In the line before the return, the calculation is done and directly printed: cout << a + b; I am wondering why you wrote that line up there, what were you planning to do with it?
27th Dec 2018, 11:54 PM
HonFu
HonFu - avatar
+ 2
int a+b; Crashes the code, because you cannot use Symbols e.g. *, +, x, %, & in varibles instead, Get rid of that line to make that varible dissapear and everything will come back together. cout << a+b; already defines the sum of the problem.
28th Dec 2018, 5:11 AM
Potato Hacker
Potato Hacker - avatar