+ 1
Why does cin, expecting an int, change the corresponding int variable to zero in case of invalid input ?
Moreover , when I give input a and Enter it takes 0 for first integer and -1098876708 code : int a,b; cout<<"enter "<<endl; cin>>a>>b; cout<<a<<" "<<b;
2 Réponses
+ 5
What is your input?
+ 1
If input "a" is 5 and input "b" is hello the output will be 5 0. Remember that in SoloLearn you must enter multiple inputs on separate lines.
#include<iostream>
using namespace std;
int main () {
int a, b;
cout << "Enter (a) and (b) " << endl;
// If user inputs
// 5 && hello
cin >> a >> b;
// The output will be
// 5 0
cout << a << " " << b << endl;
return 0;
}