0

cin

I am testing the cin operation , i have tried to insert value for two different variables, it gave the chance to insert the value for the fist one but the other one gave me a random value, what is the wrong with my code please? # include <iostream> using namespace std; int main () { int a; int b; cout << "please enter a's value:\n"; cin >> a; cout << a << endl; cout << "please add b's value: \n"; cin>> b; cout << b; return 0; } knowing that i have only inserted 5 at the first time the result was as follows : please enter a's value: 5 please add b's value: 8 from where the value of 8 has been extracted ??

23rd Jul 2018, 8:28 AM
Raghad
Raghad - avatar
2 ответов
+ 1
you have to enter both values when you start the program in SL, else it will pull some garbage value out of memory
23rd Jul 2018, 11:10 AM
hinanawi
hinanawi - avatar
0
I think it's problem with compiler, try same code on some PC IDE like CodeBlocks, and see will it work. Probably it will.
23rd Jul 2018, 8:50 AM
Dejan
Dejan - avatar