Matt <jrefactors@hotmail.com> wrote:[color=blue]
> I am writing a recursive program to draw the lines recursively, given the
> range[min,max] and number of intervals (n) between the range.[/color]
[color=blue]
> The problem is I don't know how to draw the line in point 0.375, as you see below.
> Please advise! Thanks![/color]
[color=blue]
> #include <iostream>
> using namespace std;[/color]
Sorry, but this a C newsgroup, there's also a C++ group in case you have
problems with C++. So let's replace this with
#include <stdio.h>
[color=blue]
> void draw(double min, double max, int n);[/color]
[color=blue]
> int main()
> { draw(0,1,8);
> }[/color]
You forgot to have main() return an int...
[color=blue]
> void draw(double min, double max, int n)
> { if (n != 1)
> { double mid = (max - min)/2;[/color]
You need to add the starting point of the interval here:
double mid = ( max - min ) / 2 + min;
(the mid-point between e.g. 4 and 5 is 4.5 and not just 0.5).
[color=blue]
> cout << mid << endl;[/color]
Sorry, this won't work in C, use instead
printf( "%f\n", mid );
[color=blue]
> draw(min, mid, n/2);[/color]
Now you're "drawing" the lower half of the interval but you forget to
also "draw" the upper half. You need an additional call:
draw( mid, max, n / 2 );
[color=blue]
> }
> }[/color]
Regards, Jens
--
_ _____ _____
| ||_ _||_ _|
Jens.Toerring@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | |
http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring