+ 2

#include <iostream> using namespace std; int main() {int a, b, sum= a+b; cout << "Enter 1st number \n"; cin >> a; cout << a <<

Why is my answer coming as 8??? For any nombers

4th Jul 2018, 4:24 PM
Haruki
Haruki - avatar
3 Antworten
+ 3
Thank you so much for your response
11th Jul 2018, 8:45 AM
Haruki
Haruki - avatar
+ 2
Post a link to your code inside of copy and pasting it also it’s cut off
4th Jul 2018, 4:27 PM
TurtleShell
TurtleShell - avatar
+ 2
You always get 8 because you are trying to calculate the sum before assigning any meaningful values to "a" and "b". Move the calculation to a point after you have asked for user input.
4th Jul 2018, 5:30 PM
Shadow
Shadow - avatar