+ 9
How to ask for multiple inputs in C++
So, I've been doing some random things and just chilling and thought lets code. So I wrote a code where the program will tell me which number is the largest number when you enter it. So I created a "Nested If" C++ program where three values are required by the user i.e, n1, n2 and n3. The program will evaluate which number is the largest. So the problem is, I DON'T KNOW HOW TO DO THIS!! All I knew was to write a code that'll ask you for input. So I created that code but it asks me for input just once, at the beginning only. So here I'm asking you guys how to do this. I appreciate the answers. Thank You in Advance ^-^ https://code.sololearn.com/cR6s84hDUi49/#cpp
13 Respostas
+ 6
Actually, this is the SoloLearn Console and not a regular one!
Though it seems to ask only once but you need to enter all the input in once. As SoloLearn is not itself a compiler or contains one but asks for the server to compile. So, it cannot do processing with user interface after it has begun. The thing it does as an other way round is that it requests all the information at once. A simple SOLUTION is that you need to enter all the three numbers separated by a new line. For example, if you want to enter the numbers 7, 19, -19 then type this in the input dialog box:
7
19
-19
And by the way, your code is all fine, no bugs, no errors.
Note: Try running it somewhere else, on Code::Blocks, Netbeans etc. on your computer. It will ask you for input three times only.
This glitch is also the reason why you cannot create highly interactive programs at SoloLearn except for in web. For that, you need a real compiler.
+ 7
@Naveen Maurya
Thanks for your answer, it helped.
By the way, I'm actually using PC right now and this program is working perfectly fine in every other IDE.
Though I'm not sure why Code::Blocks gives me error on "address <iostream> not found" ... ugh .. nevermind
So I've updated my code like you, @Alex and @Khushal Sahni told me to do.
Thank you all so much, You guys are really awesome ^-^ keep helping ^^
Here it is:
https://code.sololearn.com/cpHEdv2RJAUH/#cpp
+ 6
@Alex
I can't believe you spent your time to improve my useless code!
I'm honoured, Thank you so much for your attention đ
+ 4
@Alex
Thanks for your answer
but how you going to write a code where you can find the largest number out of 3 user-defined values
+ 4
@Khushal Sahni
well, that means I have to change my code from
"Please Enter this now" "Please enter some more" "Please keep entering"
to
"Please enter now, now and now"
Right?
+ 3
In the sololearn playground it takes all inputs at the beginning.
You input them all when you run it.
Either separate them by a space or by a new line
2 5 8
or
2
5
8
+ 3
well whatever thing you have to tell to the user, i think in the Sololearn playground it's gonna say only one thing "Looks like your program needs some Input, Split input into seperate lines" so i think it's a better idea to write at the top of the program, what the user has to enter in form of comments
+ 3
I'm bored because I'm just laying around being sick. So it's fine ^^
+ 3
oh get well soon @Alex !
+ 2
It works just fine, if you enter the inputs in 3 seperate line, it's just that your lines " please input first number" "please input second number" will be outputted after you give these 3 numbers seperated in different lines.
probably that's how Sololearn works, asks input only once đ
so you'll have to run it in an another programming environment if you want it to run properly, i.e. it prints " input first number" you enter the number, then it prints " input second number" and so on..... although here i think all you can do is split the input in 3 different lines and Submit :)
+ 2
https://code.sololearn.com/cPzybORgVldv/?ref=app
I modified your code a bit to make it more readable.
+ 1
thanks @khushal
0
For this task you may use cin>>a>>b....>>n; for input n number of inputs