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.
17 Respostas
+ 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;
+ 2
Thank you for all your answers, i will try all this!
0
I have already tried like this one, it doesnt works(
0
But I dont know, mb my programm isnt right, i will try to fix it
0
I have in my profile
0
Named
finding greatest of 3 numbers
0
Ok
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?
0
No, i just want to use only 3 variables
0
And no use max variable
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 :)
0
What do you mean by inserting more than one number