Having Trouble with Multiple Inputs in SoloLearn Compiler | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Having Trouble with Multiple Inputs in SoloLearn Compiler

Complier instructions for the inputs say to use a separate line to distinguish between inputs, but just hitting Enter and starting a new line between inputs does not seem to be working; the program proceeds as if I had only given it one input. Am I doing it incorrectly? I am writing in C++ if that is pertinent.

9th Nov 2018, 7:25 PM
Chris Sharrock
Chris Sharrock - avatar
8 Answers
+ 3
because your first list insertion never ends :D choose a character and break first loop when it’s inputed, then you will get your second loop as well. Let’s say you choosed char ‘e’ in first loop write: if (input == ‘e’) break; input means the name of var, where you stroring it. Then give compiler input like this: 1 4 6 e 2 7 9
10th Nov 2018, 8:59 AM
Sokrat_Poghosyan
Sokrat_Poghosyan - avatar
+ 6
In Code Playground you can enter your values as follows: 1 2 3 4 5 x // inputs for list1 1 2 3 4 5 // input for list2 Note that the 'x' is used deliberately here to trigger the fail bit in cin, in order for the first loop to break out. However you need to do: cin.clear(); cin.ignore(); Before the second while loop begins, otherwise the cin will stay on "failed" state, and refuse to accept any further input. I think the for loop down there only enumerates the items of list1, it doesn't combine the two vectors, but I know you'll get to it soon, keep it up! : )
10th Nov 2018, 11:24 AM
Ipang
+ 5
It works, But in your case- can we see your code? It may help
9th Nov 2018, 7:58 PM
Roneel
Roneel - avatar
+ 4
Yes, it reads across lines. It is better to use getline to read one single line into a string buffer and use a memory stream to read from it. For example: string s; stringstream ss; getline(cin, s); ss.str(s); while (ss >> n1) { list1.push_back(n1); } ss.clear(); You need to #include <sstream> for that.
10th Nov 2018, 4:26 AM
Leif
Leif - avatar
+ 2
Thanks Ipang, ill try that out, that wouldnt require a lot if change from what i started with. also thanks for bringing the last part to my attention. i had intended to combine them there but got sidetracked and think it went out the window lol
10th Nov 2018, 12:04 PM
Chris Sharrock
Chris Sharrock - avatar
+ 1
Yes definitely, please see below and thanks for your help with it! https://code.sololearn.com/c077reboUTuu/?ref=app
9th Nov 2018, 11:33 PM
Chris Sharrock
Chris Sharrock - avatar
+ 1
I hadnt considered that maybe the loop never ended but that makes a lot of sense. i guess the program is breaking the loop when ALL input ceases which is why it is treating two outputs as one. Thanks for the suggestions guys this gives me a lot to work with!
10th Nov 2018, 10:18 AM
Chris Sharrock
Chris Sharrock - avatar
+ 1
you’re welcome my friend :)
10th Nov 2018, 11:16 AM
Sokrat_Poghosyan
Sokrat_Poghosyan - avatar