0

How can I make two or more inputs in my C++ programm?

So, I tried smth like this one: int x; int y; int r; cin >> x; cin >> y; cin >> r; And SoloLearn input console asked me to type each input in seperate line. I did. But programm saw only my first input, I don't understand why. What should I do? Help me please.

29th Mar 2019, 5:51 PM
Maxtop1202
Maxtop1202 - avatar
17 Réponses
+ 3
Try this? ... if (x > y && x > r) cout << "The greater numbers is: " << x; if (y > x && y > r) cout << "The greater numbers is: " << y; if (r > x && r > y) cout << "The greater numbers is: " << r;
29th Mar 2019, 6:36 PM
Bodan Talev
Bodan Talev - avatar
+ 2
Thank you for all your answers, i will try all this!
29th Mar 2019, 6:43 PM
Maxtop1202
Maxtop1202 - avatar
0
I have already tried like this one, it doesnt works(
29th Mar 2019, 6:24 PM
Maxtop1202
Maxtop1202 - avatar
0
But I dont know, mb my programm isnt right, i will try to fix it
29th Mar 2019, 6:25 PM
Maxtop1202
Maxtop1202 - avatar
0
I have in my profile
29th Mar 2019, 6:27 PM
Maxtop1202
Maxtop1202 - avatar
0
Named finding greatest of 3 numbers
29th Mar 2019, 6:27 PM
Maxtop1202
Maxtop1202 - avatar
0
Ok
29th Mar 2019, 6:31 PM
Maxtop1202
Maxtop1202 - avatar
0
We can also write like #include <iostream> using namespace std; int main() { int x1,x2,x3,max; cout<<"enter numbers:"<<endl; cin>>x1>>x2>>x3; x1=max; if(x2>max) max=x2; if(x3>max) max=x3; cout<<"the max="<<max; return 0; } But i want to find another way, or there isnt?
29th Mar 2019, 6:31 PM
Maxtop1202
Maxtop1202 - avatar
0
No, i just want to use only 3 variables
29th Mar 2019, 6:35 PM
Maxtop1202
Maxtop1202 - avatar
0
And no use max variable
29th Mar 2019, 6:38 PM
Maxtop1202
Maxtop1202 - avatar
0
Yes there is! #include <iostream> using namespace std; int main() { int x1,x2,x3,max; cout<<"enter numbers:"<<endl; cin>>x1>>x2>>x3; max = x1 > x2 && x1 > x3 ? x1 : ( x2 > x3 && x2 > x1 ? x2 : x3 ); // one-line cout<<"the max="<<max; return 0; } Apologies for the messed up code :)
29th Mar 2019, 6:41 PM
#RahulVerma
#RahulVerma - avatar
0
What do you mean by inserting more than one number
29th Mar 2019, 7:52 PM
hussain