- 1

addition of two numbers after accepting from user

if i do int sum=a+b; in case of where i m adding two numbers after taking from user then it is showing incorrect answer can you please tell the reason behind it

15th Aug 2018, 3:55 PM
Isha Kansal
Isha Kansal - avatar
3 Respostas
+ 1
int a, b; std::cin >> a>> b; int sum= a+b; std::cout <<sum;
15th Aug 2018, 4:01 PM
Dlite
Dlite - avatar
+ 1
It's generally wrong to sum before receiving values. You're most likely to get 0.
16th Aug 2018, 5:07 AM
Dlite
Dlite - avatar
0
I know that it will work in this manner but I am not able to understand why it's not working if we definitely sum before accepting valued
15th Aug 2018, 7:15 PM
Isha Kansal
Isha Kansal - avatar