The answer is always 0 for some reason, I already tried this code on Microsoft Visual C++ and it worked now I'm on a Mac so I am using Eclipse.
I would really appreciate it if someone can tell me what is happening.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
int main()
{
double x = 0.0;
double y = 0.0;
double z = ( x + y );
cin >> x;
cin >> y;
cout << z;
cin.ignore();
return 0;
}
On line 8 both x and y is 0. 0+0 is 0 so the value of z is set to 0. The value of z is never changed so when you print its value on line 12 it prints 0.