+ 1

#include <iostream> using namespace std; int main() { int a, b; int sum; cout << "20 \n"; cin >> a; cout << "30 \n"; cin >> b; sum = a + b; cout << "Sum is: " << sum << endl; return 0; }

why the sum is comig wrong how to correct ir

2nd Jul 2016, 6:44 AM
devesh dangi
6 ответов
+ 1
what's that 30 and 20 are u giving inputs or what??in that case there's no need of cin statement right!!so,run the program by removing those values or cin statements..
2nd Jul 2016, 2:27 PM
siri
0
because u declared int sum; without assigning zero to it, you see when u leave it the compiler reads it as binary and miltiplies its value to give u a big number in the end and idk why that cout is 20 and 30 you always need to assign values to variables so make it int sum = 0;
2nd Jul 2016, 7:17 AM
ElemmentCG
0
both answers are wrong cant get the correct answer please run
2nd Jul 2016, 2:06 PM
devesh dangi
0
The code works. What's wrong with it?
2nd Jul 2016, 3:01 PM
Duryl
0
your code is right I thinks problem on user input get 1 input 20 and 2 input 30 then check
2nd Jul 2016, 9:51 PM
Âshvin Solanki
Âshvin Solanki - avatar
0
you should use int sum=0
2nd Jul 2016, 10:45 PM
#include<zohi>
#include<zohi> - avatar