+ 2

Why is it doing this?

im trying to get it to ask user for 2 nums and add them then output it but it gives me a weird output. any idea? https://code.sololearn.com/c03a3yRkHj4v/?ref=app

10th Apr 2017, 2:38 AM
Seth T
Seth T - avatar
2 Answers
+ 18
sum is being assigned the values of a and b before they are given values. All variables contain a garbage value before they're assigned something meaningful, which is where the weird result is coming from. Place "sum = a + b;" after the cin instead.
10th Apr 2017, 2:50 AM
Tamra
Tamra - avatar
+ 2
ohhhhh okay thank yiu man that makes alotnof sense actually 😂
10th Apr 2017, 2:51 AM
Seth T
Seth T - avatar