+ 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
15 Answers
+ 4
only use cin for one input at a time
cin >> a;
cin >> b;
+ 4
Here is an example
https://code.sololearn.com/cEU7L0otLc9Y/?ref=app
+ 4
Did you get multiple input to work?
+ 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
+ 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.
+ 3
I left the instructions in the code for you.
Read the comment and the prompt for input.
+ 2
Multiple inputs on the same line using a single cin.
Is not allow by the compiler.
+ 2
Only way for sameline without a custom input function.
https://code.sololearn.com/c43BG8VsZStZ/?ref=app
+ 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
+ 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.
+ 1
just saw.
+ 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?
+ 1
yes. i got what you sent me
+ 1
ok. thank u for the help
+ 1
@Ran
You're welcome!