Velocity Reviews > C++ > How to input 2 inputs in 1 line???

# How to input 2 inputs in 1 line???

Jay
Guest
Posts: n/a

 10-22-2003
Enter the first point coordinates: 3 4
Enter the second point coordinates: 0 0
Distance between (3.00, 4.00) and (0.00, 0.00) is 5.00

the value 3, 4, 0, 0 are the input position for users
if i program as:

{
int x1, y1;
cout << "Enter the first point coordinates: ";
cin >> x1;
cin >> y1;
return 0;
}
the x1 and y1 input position are separated in 2 lines!
how can i solve this problem???

=?ISO-8859-1?Q?Juan_Antonio_Dom=EDnguez_P=E9rez?=
Guest
Posts: n/a

 10-22-2003
Jay wrote:
> Enter the first point coordinates: 3 4
> Enter the second point coordinates: 0 0
> Distance between (3.00, 4.00) and (0.00, 0.00) is 5.00
>
> the value 3, 4, 0, 0 are the input position for users
> if i program as:
>
> {
> int x1, y1;
> cout << "Enter the first point coordinates: ";
> cin >> x1;
> cin >> y1;
> return 0;
> }
> the x1 and y1 input position are separated in 2 lines!
> how can i solve this problem???

#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main() {
double x,y;
while (1) {
cout << "Prompt:" << flush;
cin >> x >> y;
cout << "x=" << x << " y=" << y << " Module:" << sqrt(x*x+y*y) << endl;
}
return 1;
}

Karl Heinz Buchegger
Guest
Posts: n/a

 10-22-2003

Jay wrote:
>
> Enter the first point coordinates: 3 4
> Enter the second point coordinates: 0 0
> Distance between (3.00, 4.00) and (0.00, 0.00) is 5.00
>
> the value 3, 4, 0, 0 are the input position for users
> if i program as:
>
> {
> int x1, y1;
> cout << "Enter the first point coordinates: ";
> cin >> x1;
> cin >> y1;
> return 0;
> }
> the x1 and y1 input position are separated in 2 lines!
> how can i solve this problem???

Did you try the above?
Even if you have 2 seperate cin >> ...
statements you still can enter 2 numbers. cin >> ... works
by reading from the input stream what it needs to read (a number
in your case). The rest waits in the input stream until a cin >> ...
comes to fetch it.

But of course you could do:

cin >> x1 >> y1;

--
Karl Heinz Buchegger
http://www.velocityreviews.com/forums/(E-Mail Removed)

newtothis
Guest
Posts: n/a

 10-22-2003

yuo could always resort to something nasty like printf() and scanf().
They are still available in C++. You would also still have your prompt
and input on one line.

--
Posted via http://dbforums.com

Brett
Guest
Posts: n/a

 10-25-2003
Jay wrote:
> Enter the first point coordinates: 3 4
> Enter the second point coordinates: 0 0
> Distance between (3.00, 4.00) and (0.00, 0.00) is 5.00
>
> the value 3, 4, 0, 0 are the input position for users
> if i program as:
>
> {
> int x1, y1;
> cout << "Enter the first point coordinates: ";
> cin >> x1;
> cin >> y1;
> return 0;
> }
> the x1 and y1 input position are separated in 2 lines!
> how can i solve this problem???

Try this:
int main(){
int a, b;
a = 0;
b = 0;
cout << "Enter the 2 coords (space seperated):\n";
cin >> a >> b;
cout << "a: " << a << " b: " << b << endl;
return 0;
}