help my code not working

I hv code C++ but not working

my code

#include<iostream.h>
#include<graphics.h>

void grs_vertikal(int x1,int y1,int x2,int y2);
void grs_horisontal(int x1,int y1,int x2,int y2);
void grs_diagonal(int x1,int y1,int x2,int y2);

main ()
{
int vx1,vx2, vy1,vy2, vxy;
cout<< "PROGRAM MENGGAMBAR GARIS"endl << ;

cout<< "1. Garis vertikal" endl << ;
cout<< "2. Garis horisontal" endl << ;
cout<< "3. Garis diagonal" endl<< ;
cout<< endl<< "Pilih no. =";
cin>> vxy ;
switch(vxy)
{
case 1:
cout <<endl<<"masukkan variabel x1
=";
cin vx1;
cout <<endl<<"masukkan variabel x2
=";
cin vx2;
cout <<endl<<"masukkan variabel y1
=";
cin vy1;
cout <<endl<<"masukkan variabel y2
=";
cin vy2;

initwindow(1000,500);
grs_vertikal(10,10,50,50);
while (!kbhit());
closegraph();
}
void grs_vertikal(int x1,int y1,int x2,int y2)
{
int i,color;
color=255;
if(x1<x2)
{
for(i=x1;i<x2;i++)
{
putpixel(x1,i,color);
}
}
else
{
for(i=x1;i>x2;i++)
{
putpixel(y1,i,color);
}
}
}
break;

case 2:
cout <<endl<<"masukkan variabel x1
=";
cin vx1;
cout <<endl<<"masukkan variabel x2
=";
cin vx2;
cout <<endl<<"masukkan variabel y1
=";
cin vy1;
cout <<endl<<"masukkan variabel y2
=";
cin vy2;
initwindow(1000,500);
grs_horisontal(10,10,50,50);
while (!kbhit());
closegraph();
}
void grs_horisontal(int x1,int y1,int x2,int y2)
{
int i,color;
color=255;
if(x1<x2)
{
for(i=x1;i<=x2;i++)
{
putpixel(i,x1,color);
}
}
else
{
for(i=x1;i>=x2;i++)
{
putpixel(i,y1,color);
}
}
}

break;
case 3:
cout<< endl<< "masukkan variabel x1=";
cin>>vx1;
cout<< endl<< "masukkan variabel x2=";
cin>>vx2;
cout<< endl<< "masukkan variabel y1=";
cin>>vy1;
cout<< endl<< "masukkan variabel x1=";
cin>>vy2;
initwindow(1000,500);
grs_diagonal(10,10,50,50);
while (!kbhit());
closegraph();
}
void grs_diagonal(int x1,int y1,int x2,int y2)
{
int i,color;
color=255;
if(x1<x2)
{
for(i=x1;i<x2;i++)
{
x1++;
x2++;

putpixel(x1,i,color);

}
}
else
{
for(i=x1;i>x2;i++)
{
else
{
for(i=x1;i>=x2;i++)
{
x1++;
y1++;

{

putpixel(y1,i,color);
}
}
}

break;

getch();
}

can you help me whats wrong my code
Sorry dear... i have no any Idea this time.... :(
hope this helps but the first thing i noticed in this code is the cins within case 1 and case 2:

1
2
3
4
5
6
7
8
9
case 1 and case 2: // you forgot the '>>' for each cin

cout <<endl<<"masukkan variabel x1=";
cin vx1; cout <<endl<<"masukkan variabel x2=";
cin >> vx2;
cout <<endl<<"masukkan variabel y1=";
cin >> vy1;
cout <<endl<<"masukkan variabel y2=";
cin >> vy2;


also would recommend looking on the format options and chosing <> button to put your code like how i did above. Kinda makes it hard to read how you just submitted it as such but np. Also would say take a look at the endl. could be a error in any of those sections that may make the code mess up. The way I was taught about endl was set as cout<<"whatever you want to tell the user"<<endl; or even so it all depends. http://www.cplusplus.com/reference/ostream/endl/
also next question i have to ask is where are you defining kbhit? as well as putpixel and such. Just want to make sure about that. is it associated with your graphics.h?

those are the first things that i noticed that caught my attention but please do explain what issues you have had as well as what you have noticed. cant help if your not detailed ok?
Last edited on
kbhit and putpixel about graphics.h but I dont know to combine 3 function line horisontal, vertical and diagonal but thanks ur attention my friends
Topic archived. No new replies allowed.