473,407 Members | 2,320 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,407 software developers and data experts.

recursively draw the lines

I am writing a recursive program to draw the lines recursively, given the
range[min,max] and number of intervals (n) between the range.

The problem is I don't know how to draw the line in point 0.375, as you see below.
Please advise! Thanks!
#include <iostream>
using namespace std;

void draw(double min, double max, int n);

int main()
{ draw(0,1,8);
}

void draw(double min, double max, int n)
{ if (n != 1)
{ double mid = (max - min)/2;
cout << mid << endl;
draw(min, mid, n/2);
}
}
The program output:
0.5
0.25
0.125

Here's the expected output:
0.5
0.25
0.125
0.375
0.75
0.625
0.875
Jul 19 '05 #1
2 2460

"Matt" <jr********@hotmail.com> a écrit dans le message de
news:ba*************************@posting.google.co m...
I am writing a recursive program to draw the lines recursively, given the
range[min,max] and number of intervals (n) between the range.

The problem is I don't know how to draw the line in point 0.375, as you see below. Please advise! Thanks!
#include <iostream>
using namespace std;

void draw(double min, double max, int n);

int main()
{ draw(0,1,8);
}

void draw(double min, double max, int n)
{ if (n != 1)
{ double mid = (max - min)/2;
cout << mid << endl;
draw(min, mid, n/2);
}
}
The program output:
0.5
0.25
0.125

Here's the expected output:
0.5
0.25
0.125
0.375
0.75
0.625
0.875


shouldn't you call draw(mid, max too, n/2) ?
Jul 19 '05 #2
".oO LGV Oo." wrote:


shouldn't you call draw(mid, max too, n/2) ?


draw(mid, max, n - n/2);

n could be odd.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 19 '05 #3

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

Similar topics

5
by: Matt | last post by:
I am writing a recursive program to draw the lines recursively, given the range and number of intervals (n) between the range. The problem is I don't know how to draw the line in point 0.375, as...
4
by: Mathieu Chavoutier | last post by:
Hi. I would like to do something like paint. I try to draw a line. I want, like paint, that when I clickdown, it begins to draw the line, and then, when I move the mouse, the line follow the...
7
by: Mark Ingram | last post by:
Hi, how can i draw a rounded rectange, with a border within a specified area? i.e. if i have a Rectangle with width and height of 100, how can i draw a rectange with 2 pixel border inside of the...
10
by: kaczmar2 | last post by:
Hey there, I have a large image in a browser window, and I would like a way to overlay grid lines on top of the image, so a user can show the grid or hide the grid lines. The grid would cover...
10
by: wazzup | last post by:
C++ is new to me and I'm trying solve this problem but get stuck. Please help me out. Below is the task and after that is what i got so far. Create a program to print nested squares Input:...
9
by: zhaow | last post by:
Hi, All Greetings! I want to develop as appllication that requires a line-drawing function in the blank area between two forms. I have looked up the MSDN, it says that a graphics object need a...
4
by: hastalavista | last post by:
HI I'm very new to C# and I've got a big project to do in C# for uni until july. I've been trying do draw lines in C# (arrows to be precise). I can draw them allright but once I minimize the...
8
by: Anuhas | last post by:
Dear experts, I have used buttons to indicate certain locations on a map.(Just a picture used as form background) I am going to draw lines...
0
by: Anuhas | last post by:
Dear Experts, I need to draw lines. But I have to make a class for this. I know how to draw lines in direct methods. i.e. Graphics g =...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.