0

Different output result everytime

I wrote this C++ code , everytime i run it it shows different output , please help #include<iostream> using namespace std; int main() { int a,b; int c = a + b; //please inter any 2 numbers cin >> a >> b; cout << "-adding " << a << " to " << b << "\n please wait... \n"; cout << "\n -addition result is: " << c; cout << "\n -operarion finished" << "\n -thank you for using my app"; return 0; }

15th Jul 2020, 12:45 PM
UG.2
UG.2 - avatar
3 Respostas
+ 1
You are adding values before you even get them from the user. Thus , they a and b give out garbage values as they are not assigned. So , write like this, cin >> a >> b; int c = a + b; instead of int c = a + b; cin >> a >> b; And please refer the link to your code instead of copy/pasting it. Makes it easy to debug. Have a good day, Ćheyat
15th Jul 2020, 12:52 PM
Saphal Poudyal
Saphal Poudyal - avatar
0
Hmm
15th Jul 2020, 12:46 PM
UG.2
UG.2 - avatar
0
Because you are adding c=a+b before taking input from user. so correction should be: cin>>a>>b; int c=a+b;
15th Jul 2020, 12:54 PM
The future is now thanks to science
The future is now thanks to science - avatar