Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

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???
 
Reply With Quote
 
 
 
 
=?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;
}

 
Reply With Quote
 
 
 
 
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)
 
Reply With Quote
 
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
 
Reply With Quote
 
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;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
google URL-based searchplugins can have *two* inputs as_q= q= Splibbilla Firefox 0 04-17-2005 11:15 PM
pullup on inputs Max VHDL 0 09-25-2003 09:49 AM
Anybody know how I would code an error statement when a user inputs an invalid input. jeff regoord C Programming 10 09-13-2003 01:16 PM
Coding style to prioritize certain inputs Willem Oosthuizen VHDL 5 09-04-2003 05:17 PM



Advertisments