How to input 2 inputs in 1 line???

J

Jay

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?=

Jay said:
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;
}
 
K

Karl Heinz Buchegger

Jay said:
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;
 
N

newtothis

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.
 
B

Brett

Jay said:
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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top