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; }
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
0
Hmm
0
Because you are adding c=a+b before taking input from user.
so correction should be:
cin>>a>>b;
int c=a+b;