Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I wrote a code, but it does not show triangle, could you please fix it to show s

ID: 3637407 • Letter: I

Question

I wrote a code, but it does not show triangle, could you please fix it to show sierpinski triangle. But please do not change the x and y value of if and else if statement because they are all right.
the other parts should be wrong, but I cannot find out. Thank you

#include <iostream>
using namespace std;
#include <cstdlib>
int main() {
double x=0.5; double y=0.0;
const int m = 10000; time_t now; now = time(NULL);
srand48(now);
for(int i=0; i<m;i++)
{double r = drand48();
if(r<0.02){
x=0.5; y=0.27*y;
}
else if (0.02 <= r && r<=0.17){
x=-0.139*x + 0.263*y +0.57;
y=0.246*x + 0.224*y - 0.036;
}
else if (0.17<r && r<=0.3){
x=0.17*x - 0.215*y + 0.408;
y=0.222*x + 0.176*y + 0.0893;
}
else if (0.3<r && r<1){
x=0.781*x + 0.034*y + 0.1075;
y=-0.032*x + 0.739*y + 0.27;
}
cout<<x<<" "<<y<<endl;
}}

Explanation / Answer

I have another program for Sierpinski triangle if it can help you: #include #include #include #include #include void DrawSierpinski(void); void main(void) { int gd=VGA; int gm=VGAHI; initgraph(&gd, &gm, "\tc\bgi"); DrawSierpinski(); getch(); } void DrawSierpinski(void) { char Direct; int iterate; unsigned int x1, y1, x2, y2; x1 = x2 = 320; y1 = y2 = 0; for(iterate = 0; iterate < 10000; iterate++) { Direct = random(3); if(Direct == 0) { x1 = (x2 + 320) / 2; y1 = (y2 + 0) / 2; } else if(Direct == 1) { x1 = (x2 + 0) / 2; y1 = (y2 + 480) / 2; } else if(Direct == 2) { x1 = (x2 + 640) / 2; y1 = (y2 + 480) / 2; } putpixel(x1, y1, WHITE); x2 = x1; y2 = y1; } }