recursively draw the lines

M

Matt

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
 
O

.oO LGV Oo.

Matt said:
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) ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top