Code
#include <iostream>
using namespace std;
int main()
{
int sum;
int n1;
int n2;
cout << "Input n1 => ";
cin >> n1; // 1
cout << "Input n2 => ";
cin >> n2; // 2
sum = sum + n1;
sum = sum + n2;
cout << "sum: " << sum << endl; // 32769
return 0;
}
Sample output
Input n1 => 1
Input n2 => 2
sum: 32769
Question: Why and how to get the correct output which is “sum: 3”?
No comments:
Post a Comment