473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to input 2 inputs in 1 line???

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???
Jul 19 '05 #1
4 8183


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
kb******@gascad.at
Jul 19 '05 #2
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;
}

Jul 19 '05 #3

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
Jul 19 '05 #4
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;
}

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gregg | last post by:
Hello all, I have been banging my head over a problem that I am having reading a comma seperated file (CSV) that can contain from 1 to 10,000 records. My code snipit is as follows: **Start...
10
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does...
2
by: bildad | last post by:
The following 'book example' of validating input seems to be incomplete. Since it is a beginner's book it may be intentional for simplicity. But I would like to know how to make this program work...
8
by: Radith | last post by:
Hi All, I have a number guessing game in which users try to guess a random number. Obviously, input is required of type int. BUT, when a user inputs a string the program will result in an...
7
by: ero | last post by:
Is it possible to input values into a web form from an external source like a client-side javascript? There is a web site that I'm viewing where I have to enter 5 values in the form. 4 of the...
6
by: effendi | last post by:
I have an array for of input names. Input1 , input 2 etc. Can I pass the input names in a loop like document.all.value="xxxx" The problem is document.all cannot be used in Safari/firefox, I...
6
by: Vortexmind | last post by:
Hi all I was wondering if this is possible in Javascript. I want to make a bookmarklet. When a user launches it, it tells the user to select an element in the page (for example a textarea) with...
7
by: Danielle | last post by:
All - I was asked to work on a project converting some weather data. The program used to convert the data is written in Quick Basic. I am only a novice programmer and while I can see from the...
11
by: waffle.horn | last post by:
Hi, if this makes sense i want to create a function that can be called so that it reads a single line from a file, then after using the information destroys it. Such that when the function is...
116
by: dmoran21 | last post by:
Hi All, I am working on a program to take input from a txt file, do some calculations, and then output the results to another txt file. The program that I've written compiles fine for me, however,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.