+ 1

Help?

can u explain to me sentence after sentence why i get the following result? and how i suppose to input 2 variables at the same time? #include <iostream> using namespace std; int main() { int a,b; cout << "Please enter a number \n"; cin >> a>>b; cout << a<<b; return 0; } input: 3 output: 32686816

14th Oct 2017, 12:23 PM
Ran Dahn
Ran Dahn - avatar
15 ответов
+ 4
only use cin for one input at a time cin >> a; cin >> b;
14th Oct 2017, 12:43 PM
Manual
Manual - avatar
14th Oct 2017, 12:51 PM
Manual
Manual - avatar
+ 4
Did you get multiple input to work?
14th Oct 2017, 1:01 PM
Manual
Manual - avatar
+ 4
C++ resources - you should use a C++ IDE to practice. - the playground is limited https://www.sololearn.com/discuss/459759/?ref=app IDE ------ code blocks https://www.sololearn.com/discuss/608805/?ref=app visual studio https://www.sololearn.com/discuss/410578/?ref=app
14th Oct 2017, 1:04 PM
Manual
Manual - avatar
+ 3
Also the numbers you got after 3, for output. That is from the error caused by using cin for a and b in one statement.
14th Oct 2017, 12:54 PM
Manual
Manual - avatar
+ 3
I left the instructions in the code for you. Read the comment and the prompt for input.
14th Oct 2017, 12:56 PM
Manual
Manual - avatar
+ 2
Multiple inputs on the same line using a single cin. Is not allow by the compiler.
14th Oct 2017, 1:07 PM
Manual
Manual - avatar
+ 2
Only way for sameline without a custom input function. https://code.sololearn.com/c43BG8VsZStZ/?ref=app
14th Oct 2017, 1:09 PM
Manual
Manual - avatar
+ 1
if you want multiple inputs you should separate them with spaces Input: 3 12 will generate Output: 312 because you don't separate your output variables you should rewrite the output statement like this cout << a << " " << b; this will generate output: 3 12
14th Oct 2017, 12:50 PM
bogdan
bogdan - avatar
+ 1
thanks, but what happens if i enter one input when i need to enter two inputes? in my code: a=3; b get a random number? because i get output but i don't understand where it cames from.
14th Oct 2017, 12:54 PM
Ran Dahn
Ran Dahn - avatar
+ 1
just saw.
14th Oct 2017, 12:57 PM
Ran Dahn
Ran Dahn - avatar
+ 1
a new question: is there an option in which i can input two variables at the same line? accordingly, i see that i can't add more the one insertion operator "<<" in cin, is that right?
14th Oct 2017, 1:02 PM
Ran Dahn
Ran Dahn - avatar
+ 1
yes. i got what you sent me
14th Oct 2017, 1:03 PM
Ran Dahn
Ran Dahn - avatar
+ 1
ok. thank u for the help
14th Oct 2017, 1:08 PM
Ran Dahn
Ran Dahn - avatar
+ 1
@Ran You're welcome!
14th Oct 2017, 1:10 PM
Manual
Manual - avatar