+ 1
Why my code cannot function?
6 ответов
+ 13
You should not add a and b to d before cin.
int a,b, d;
cin >> a >> b;
d = a + b;
cout << d;
+ 7
We want to take user input, and then add the two numbers, not the other way around.
+ 7
Exactly. Check on what garbage values in uninitialised variables are:
https://www.quora.com/What-do-you-mean-by-a-garbage-value-in-a-variable
+ 2
thank you very much! 😀Hatsy Rei
+ 1
I have a idea! (when "d=a+b is before cin) Is it becuz at that moment, variable a and variable b have no value?So the value of variable d become something weird.No help if I assign a and b some value. Am I right?
0
Is it the format? or there is other explanation?