I started teaching myself C++ today and I wrote following codes so as to make a basic calculator that does addition but its not functioning. everytime i build it and run it on codeblocks the value is wrong and random. Can anybody tell me whats wrong in this program?
thanks.
#include <iostream>
usingnamespace std;
int main()
{
int a;
int b;
int c;
int d;
int sum;
cout << "Please enter a number \n";
cin >> a;
cout << "please enter another number.. \n";
cin >> b;
cout << "please enter another number.. \n";
cin >> c;
cout << "please enter another number.. \n";
cin >> d;
sum = a+b+c+d;
cout << "here i present the sum of those numbers \n"
cout << sum;
return 0;
}
doesn't code blocks have the option of using different compilers?
not true. you can
edit: but most people commonly use mingw
edit 2: and once he fixes the semicolon issue, a program that small shouldnt make a difference what compiler compiles it.
it might matter on what compiler he is using cause doesn't code blocks have the option of using different compilers?
There's nothing in the posted code that makes any use of compiler extensions or implementation-specific behaviour. So assuming the OP is using a proper C++ compiler, there's no reason to think the choice of compiler will make a difference.
Until the OP gives us something more to go on, it's going to be difficult to diagnose. And s/he seems to have gone quiet.