473,385 Members | 1,347 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,385 software developers and data experts.

Outputting Points between numbers

Im new to programming, expecially c++. I started off in python but really just know the basics.

My question is, how would i go about writing a program that would output all of the numbers (whole numbers) on a plane between X and Y, saw 0,0 and 10,10?

I can get my code to write the basics from 0-10 with a while loop, but only for 1 axis.

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2.  
  3.  
  4. using std::cin;
  5. using std::cout;
  6.  
  7. int main()
  8. {
  9.  int upper_left;
  10.  int upper_right;
  11.  int lower_left;
  12.  int lower_right;
  13.  
  14.  cout<<"Enter Upper Left ";
  15.  cin >>upper_left;
  16.  
  17.  cout<<"Enter Upper Right ";
  18.  cin >>upper_right; 
  19.  
  20.  cout<<"Enter Lower Left ";
  21.  cin>>lower_left;
  22.  
  23.  cout<<"Enter Lower Right ";
  24.  cin>>lower_right;
  25.  
  26.  
  27.  
  28.  
  29.  
  30.         while  (upper_left <= lower_left)
  31. {
  32.         cout << upper_left  <<"," << upper_right <<"  ";
  33.         upper_left++;
  34. }
  35.  
im not sure where to go from here? How would i move along the other axis.

Im sorry if this isnt clear, i have been up extremely late the past few nights and am running on little sleep. I would appreciate any help or pointers here. Thanks
Feb 27 '08 #1
7 1382
sicarie
4,677 Expert Mod 4TB
If I could just take a minute to rephrase what you are asking, make sure I have the question clear - you want to take a group of coordinates (more than one set of x,y pairs), and print them each out on the console (not drawn using some graphics library)?

If that is correct, I would recommend using two for loops to iterate through your grid. (The following is in pesudocode) As for loops go, you're going to want:

Expand|Select|Wrap|Line Numbers
  1. for_loop_for_horizontal                                 // starting left, going right
  2.    for_loop_for_vertical                                // starting top, going down
  3.        check to see if indicies match any coordinates
  4.        but if not don't forget to print out a " " space char
  5.  
You could put in various time-saving checks - like a check in the beginning of each horizontal to see if there is a coordinate, and if not, just jump to the next line, etc... There are probably other ways to do it, but I don't know any off the top of my head (at least none involving other libraries).

Or did I completely mis-read your question?
Feb 27 '08 #2
thanks for your reply. I want to find the numbers between between 2 sets of ordered pairs. So between say -3,5 and 5,-3 would be

-3, 5 -2, 5 -1, 5 0, 5 1, 5 2, 5 3, 5 4, 5 5, 5
-3, 4 -2, 4 -1, 4 0, 4 1, 4 2, 4 3, 4 4, 4 5, 4
-3, 3 -2, 3 -1, 3 0, 3 1, 3 2, 3 3, 3 4, 3 5, 3
-3, 2 -2, 2 -1, 2 0, 2 1, 2 2, 2 3, 2 4, 2 5, 2
-3, 1 -2, 1 -1, 1 0, 1 1, 1 2, 1 3, 1 4, 1 5, 1
-3, 0 -2, 0 -1, 0 0, 0 1, 0 2, 0 3, 0 4, 0 5, 0
-3,-1 -2,-1 -1,-1 0,-1 1,-1 2,-1 3,-1 4,-1 5,-1
-3,-2 -2,-2 -1,-2 0,-2 1,-2 2,-2 3,-2 4,-2 5,-2
-3,-3 -2,-3 -1,-3 0,-3 1,-3 2,-3 3,-3 4,-3 5,-3

The code i currently have will give me the first line. I dont know how to proceed from there
Feb 27 '08 #3
sicarie
4,677 Expert Mod 4TB
any ideas here guys?
Dude, you posted your question half an hour ago. Patience is a virtue.
Feb 27 '08 #4
And sorry for that last post. I meant to edit that out, i realized that was extremely impatient; expecially for how unclear i may have been.
Feb 27 '08 #5
sicarie
4,677 Expert Mod 4TB
And sorry for that last post. I meant to edit that out, i realized that was extremely impatient; expecially for how unclear i may have been.
Ugh, that's a really ugly looking input file. Are you manually inserting those? That will get nasty if you try to read them in from file and parse each one, due to the space after the comma. You will have to set some sort of "b_commaFound" boolean flag so that you know when you've hit a pair or not. And you won't be able to cin, you'll have to parse the line out.

Also, are there clear constraints to how you print these out? As in, do you need them in a normal, |_ - shaped x,y coordinate graph? Or are you just messing around and wondering how you can print them out?

I told you how you could print them out on the console. If you were looking for the L-shaped graph, you could reverse the horizontal, start it counting from the "top" that way it would logically appear correct, but it would write top to bottom.
Feb 27 '08 #6
Those numbers are meant to be the output, not the input. The program i am trying to generate will take (x1,y1) and (x2.y2) and find every possible point that exists between them.

For input -3,5 5,-3 I would expect an output of:
-3, 5 -2, 5 -1, 5 0, 5 1, 5 2, 5 3, 5 4, 5 5, 5
-3, 4 -2, 4 -1, 4 0, 4 1, 4 2, 4 3, 4 4, 4 5, 4
-3, 3 -2, 3 -1, 3 0, 3 1, 3 2, 3 3, 3 4, 3 5, 3
-3, 2 -2, 2 -1, 2 0, 2 1, 2 2, 2 3, 2 4, 2 5, 2
-3, 1 -2, 1 -1, 1 0, 1 1, 1 2, 1 3, 1 4, 1 5, 1
-3, 0 -2, 0 -1, 0 0, 0 1, 0 2, 0 3, 0 4, 0 5, 0
-3,-1 -2,-1 -1,-1 0,-1 1,-1 2,-1 3,-1 4,-1 5,-1
-3,-2 -2,-2 -1,-2 0,-2 1,-2 2,-2 3,-2 4,-2 5,-2
-3,-3 -2,-3 -1,-3 0,-3 1,-3 2,-3 3,-3 4,-3 5,-3
Feb 27 '08 #7
sicarie
4,677 Expert Mod 4TB
Those numbers are meant to be the output, not the input. The program i am trying to generate will take (x1,y1) and (x2.y2) and find every possible point that exists between them.

For input -3,5 5,-3 I would expect an output of:
-3, 5 -2, 5 -1, 5 0, 5 1, 5 2, 5 3, 5 4, 5 5, 5
-3, 4 -2, 4 -1, 4 0, 4 1, 4 2, 4 3, 4 4, 4 5, 4
-3, 3 -2, 3 -1, 3 0, 3 1, 3 2, 3 3, 3 4, 3 5, 3
-3, 2 -2, 2 -1, 2 0, 2 1, 2 2, 2 3, 2 4, 2 5, 2
-3, 1 -2, 1 -1, 1 0, 1 1, 1 2, 1 3, 1 4, 1 5, 1
-3, 0 -2, 0 -1, 0 0, 0 1, 0 2, 0 3, 0 4, 0 5, 0
-3,-1 -2,-1 -1,-1 0,-1 1,-1 2,-1 3,-1 4,-1 5,-1
-3,-2 -2,-2 -1,-2 0,-2 1,-2 2,-2 3,-2 4,-2 5,-2
-3,-3 -2,-3 -1,-3 0,-3 1,-3 2,-3 3,-3 4,-3 5,-3
Okay, I did read your question wrong. Sorry about that. Okay, that looks pretty easy, it's a modification of what I posted. You just start with the array index of the "higher," and iterate down through it, printing out each index, which will be each coordinate.
Feb 27 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Jacek Dziedzic | last post by:
Hello! I have a piece of code that needs to display a formatted table of pointers using streams, with the pointers represented as hex values. It looks more or less like this: #include...
3
by: snow.carriers | last post by:
Let me first state that I'm using Borland Turbo C++, it's relatively old so the new string methods won't work. Anyways, first I'm trying to collect a line of a string (with numbers, letters,...
8
by: bevanward | last post by:
Hi all I have a large data set of points situated in 3d space. I have a simple primary key and an x, y and z value. What I would like is an efficient method for finding the group of points...
16
by: John Salerno | last post by:
Here's my new project: I want to write a little script that I can type at the terminal like this: $ scriptname package1 where scriptname is my module name and any subsequent arguments are the...
12
by: erikcw | last post by:
Hi all, I have a collection of ordered numerical data in a list. The numbers when plotted on a line chart make a low-high-low-high-high-low (random) pattern. I need an algorithm to extract the...
6
by: flyaway888 | last post by:
Hey, I have a function that compares 2 arrays with 6 numbers in each and outputs the matching numbers. I have written a function that does this but I need to output the numbers in ascending order...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
17
by: Matt | last post by:
Hello. I'm having a very strange problem that I would like ot check with you guys. Basically whenever I insert the following line into my programme to output the arguments being passed to the...
5
by: almurph | last post by:
Hi everyone, I'm trying to output some numbers to an Excel file. the first number in A1 the second in A2, you know like this: 1 2 3 4
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. 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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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

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.