BGI error: Graphics not initialized (use initgraph)

this program is compiling without any errors...but is does not run...c

Page 1 of 1

6 Replies - 28379 Views - Last Post: 30 April 2009 - 05:25 PM Rate Topic: -----

#1 divya272  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 15-July 07

BGI error: Graphics not initialized (use initgraph)

Posted 15 July 2007 - 07:49 AM


/*Project on Ticket Reservation in a Cinema Complex*/
# include <fstream.h>
# include <conio.h>
# include <dos.h>
# include <process.h>
# include <stdio.h>
# include <graphics.h>
# include <string.h>
 
void graph()
	 {
	 int gdriver=DETECT,gmode;
	 initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
}
 
int xco,yco;
char str[30];
void setposition(int x, int y)
	 {
	 xco=x; yco=y;
	 }
 
 
 
void settext(char s[])
	 {
	 strcpy(str, s);
	 }
 
struct cast
	 {
	 char n_a[40];
	 char n_ac[40];
	 char n_d[40];
	 char n_o[100];
	 };
 
 
class hall
	 {
	 protected:
	 cast c;
	 float t;
	 char grade[2];
	 public:
	 char name[100];
	 void input();
	 void display();
	 void f_display();
	 };
void hall::input()
	 {
	 cout<<"ENTER THE NAME OF THE FILM:";
	 gets(name);
	 cout<<"ENTER ACTOR NAME:";
	 gets(c.n_a);
	 cout<<"ENTER ACTRESS NAME:";
	 gets(c.n_ac);
	 cout<<"ENTER DIRECTOR NAME:";
	 gets(c.n_d);
	 cout<<"ENTER OTHERS:";
	 gets(c.n_o);
	 cout<<"ENTER THE GRADE GIVEN TO FILM BY CENSOR BOARD:";
	 gets(grade);
	 cout<<"ENTER THE TIME LIMIT OF FILM:";
	 cin>>t;
	 }
 
	  void hall::display()
	 {
	 clrscr();
	 puts(name);
	 cout<<"\n\t*******";
	 cout<<"\n\tCASTING";
	 cout<<"\n\t*******";
	 cout<<"\nACTOR NAME :\t\t\t";
	 puts(c.n_a);
	 cout<<"ACTRESS NAME :\t\t\t";
	 puts(c.n_ac);
	 cout<<"DIRECTOR NAME :\t\t\t";
	 puts(c.n_d);
	 cout<<"OTHERS :\t\t\t";
	 puts(c.n_o);
	 cout<<"GRADE GIVEN(BY CENSOR BOARD) :\t";
	 puts(grade);
	 cout<<"TIME LIMIT OF FILM :\t\t";
	 cout<<t;
	 }
 
void hall::f_display()
	 {
	 clrscr();
	 graph();
	 cleardevice();
	 int size=8,style=GOTHIC_FONT;
	 graph();
	 settext("CINEMA");
	 settextstyle(style,HORIZ_DIR,size);
	 setposition(0,22);
	 moveto(xco,yco);
	 setcolor(BLUE);
	 //setbkcolor(BLUE);
	 outtext(str);
 
	 settext("COMPLEX");
	 settextstyle(style,HORIZ_DIR,size);
	 setposition(0,122);
	 moveto(xco,yco);
 
	 outtext(str);
 
	 int s=4,st=TRIPLEX_FONT;
	 settext(name);
	 settextstyle(st,HORIZ_DIR,s);
	 setposition(0,300);
	 moveto(xco,yco);
	 setcolor(RED);
	 outtext(str);
	 setcolor(4);
	 setfillstyle(4,RED);
	 bar3d(425,-10,700,500,1,1);
	 bar3d(430,-10,700,500,1,1);
	 bar3d(435,-10,700,500,1,1);
	 bar3d(440,-10,700,500,1,1);
	 bar3d(445,-10,700,500,1,1);
	 bar3d(450,-10,700,500,1,1);
 
	 }
class seats:public hall
	 {
	 public:
	 int bal;
	 int lower;
	 int upper;
 
	 seats()
		  {
		  bal=lower=upper=0;
		  }
	 void b_reserve(int num);
	 void u_reserve(int num);
	 void l_reserve(int num);
	 void reserve(int num);
	 void b_cancel(int num);
	 void u_cancel(int num);
	 void l_cancel(int num);
	 ~seats()
		  {
		  }
	 };
void seats::reserve(int num)
	 {
	 graph();
	 cleardevice();
	 int i,j,k,l,m,n;
 
	 setcolor(8);
	 setfillstyle(8,BLUE);
	 bar3d(425,-10,700,500,1,1);
	 i=50,j=40,k=100,l=55;
	 for(j=40,l=55;j<=450,l<=465;j+=30,l+=30)
		  {
		  for(i=50,k=100;i<=330,k<=400;i+=70,k+=70)
			   {
			   bar3d(i,j,k,l,1,1);
			   }
		  }
	  int s=0;
	 gotoxy(55,10);
	 s=num;
	 int w=0;
	 for(j=40,l=55;j<=450,l<=465;j+=30,l+=30)
		  {
		  for(i=50,k=100;i<=330,k<=400;i+=70,k+=70)
			   {
			   w+=1;
			   if(w>=s+1)
			   {
			   break;
			   }
			   setcolor(2);
			   setfillstyle(2,2);
			   bar3d(i,j,k,l,1,1);
			   }
		  }
	 }
 
 
void seats::b_reserve(int num)
	 {
	 reserve(bal);
	 if((bal+num)<=70)
		  {
		  bal+=num;
		  closegraph();
		  clrscr();
		  reserve(bal);
		  gotoxy(55,10);
		  cout<<"***************";
		  gotoxy(55,11);
		  cout<<"  RESERVATION";
		  gotoxy(55,12);
		  cout<<"   COMPLETED";
		  gotoxy(55,13);
		  cout<<"***************";
		  gotoxy(55,16);
		  cout<<"AMOUNT TO BE PAID";
		  gotoxy(56,17);
		  cout<<"Rs."<<num*120;
		  getch();
		  }
		  else
		  {
		  clrscr();
		  closegraph();
		  reserve(bal);
		  gotoxy(55,11);
		  cout<<" CANNOT";
		  gotoxy(55,12);
		  cout<<" RESERVE";
		  getch();
		  }
	 closegraph();
	 }
void seats::u_reserve(int num)
	 {
	 reserve(upper);
	 if((upper+num)<=70)
		  {
		  upper+=num;
		  closegraph();
		  clrscr();
		  reserve(upper);
		  gotoxy(55,10);
		  cout<<"***************";
		  gotoxy(55,11);
		  cout<<"  RESERVATION";
		  gotoxy(55,12);
		  cout<<"   COMPLETED";
		  gotoxy(55,13);
		  cout<<"***************";
		  gotoxy(55,16);
		  cout<<"AMOUNT TO BE PAID";
		  gotoxy(56,17);
		  cout<<"Rs."<<num*80;
 
		  getch();
		  }
		  else
		  {
		  clrscr();
		  closegraph();
		  reserve(upper);
		  gotoxy(55,11);
		  cout<<" CANNOT";
		  gotoxy(55,12);
		  cout<<" RESERVE";
		  getch();
		  }
	 closegraph();
 
	 }
 
void seats::l_reserve(int num)
	 {
	  reserve(lower);
	 if((lower+num)<=70)
		  {
		  lower+=num;
		  closegraph();
		  clrscr();
		  reserve(lower);
		  gotoxy(55,10);
		  cout<<"***************";
		  gotoxy(55,11);
		  cout<<"  RESERVATION";
		  gotoxy(55,12);
		  cout<<"   COMPLETED";
		  gotoxy(55,13);
		  cout<<"***************";
		  gotoxy(55,16);
		  cout<<"AMOUNT TO BE PAID";
		  gotoxy(56,17);
		  cout<<"Rs."<<num*20;
 
		  getch();
		  }
		  else
		  {
		  clrscr();
		  closegraph();
		  reserve(lower);
		  gotoxy(55,11);
		  cout<<" CANNOT";
		  gotoxy(55,12);
		  cout<<" RESERVE";
		  getch();
		  }
	 closegraph();
 
	  }
void seats::b_cancel(int num)
	 {
	 reserve(bal);
	 if((bal-num)>=0)
		  {
		  bal-=num;
		  closegraph();
		  clrscr();
		  reserve(bal);
		  gotoxy(55,10);
		  cout<<"***************";
		  gotoxy(55,11);
		  cout<<"  CANCELATION";
		  gotoxy(55,12);
		  cout<<"   COMPLETED";
		  gotoxy(55,13);
		  cout<<"***************";
		  gotoxy(55,16);
		  cout<<"TICKET AMOUNT ";
		  gotoxy(56,17);
		  cout<<"Rs."<<num*120;
		  getch();
		  }
		  else
		  {
		  clrscr();
		  closegraph();
		  reserve(bal);
		  gotoxy(55,11);
		  cout<<" CANNOT";
		  gotoxy(55,12);
		  cout<<" CANCEL";
		  getch();
		  }
	 closegraph();
	 }
void seats::l_cancel(int num)
	 {
	 reserve(lower);
	 if((lower-num)>=0)
		  {
		  lower-=num;
		  closegraph();
		  clrscr();
		  reserve(lower);
		  gotoxy(55,10);
		  cout<<"***************";
		  gotoxy(55,11);
		  cout<<"  CANCELATION";
		  gotoxy(55,12);
		  cout<<"   COMPLETED";
		  gotoxy(55,13);
		  cout<<"***************";
		  gotoxy(55,16);
		  cout<<"TICKET AMOUNT ";
		  gotoxy(56,17);
		  cout<<"Rs."<<num*80;
 
		  getch();
		  }
		  else
		  {
		  clrscr();
		  closegraph();
		  reserve(lower);
		  gotoxy(55,11);
		  cout<<" CANNOT";
		  gotoxy(55,12);
		  cout<<" CANCEL";
		  getch();
		  }
	 closegraph();
	 }
void seats::u_cancel(int num)
	 {
	 reserve(upper);
	 if((upper-num)>=0)
		  {
		  upper-=num;
		  closegraph();
		  clrscr();
		  reserve(upper);
		  gotoxy(55,10);
		  cout<<"***************";
		  gotoxy(55,11);
		  cout<<"  CANCELATION";
		  gotoxy(55,12);
		  cout<<"   COMPLETED";
		  gotoxy(55,13);
		  cout<<"***************";
		  gotoxy(55,16);
		  cout<<"TICKET AMOUNT ";
		  gotoxy(56,17);
		  cout<<"Rs."<<num*20;
 
		  getch();
		  }
		  else
		  {
		  clrscr();
		  closegraph();
		  reserve(upper);
		  gotoxy(55,11);
		  cout<<" CANNOT";
		  gotoxy(55,12);
		  cout<<" CANCEL";
		  getch();
		  }
	 closegraph();
	 }
 
 
 
 void main()
 {
 clrscr();
 hall h1;
 seats s;
 int ch,c,num;
 char d,e;
 char h;
 h='y';
 fstream f;
 f.open("cinema.dat",ios::in|ios::out|ios::app|ios::binary);
 ch=1;
 while(ch==1||ch==2||ch==3||ch==4||ch==5)
 {
 clrscr();
 closegraph();
 s.f_display();
 gotoxy(58,10);
 cout<<"MAIN MENU";
 gotoxy(58,11);
 cout<<"*********";
 gotoxy(58,11);
 cout<<"1)ABOUT FILM";
 gotoxy(58,13);
 cout<<"2)RESERVATION";
 gotoxy(58,15);
 cout<<"3)CANCELLATION";
 gotoxy(58,17);
 cout<<"4)AMOUNT COLLECTED";
 gotoxy(58,18);
 cout<<"ANY OTHER TO QUIT";
 gotoxy(58,19);
 cout<<"ENTER CHOICE:";
 cin>>ch;
 
 switch(ch)
	 {
 
		   case 1:
		  {
		  closegraph();
		  clrscr();
		  s.input();
		  f.close();
		  gotoxy(58,10);
		  cout<<"FILM MENU";
		  gotoxy(58,11);
		  cout<<"*********";
		  gotoxy(58,13);
		  cout<<"1)CHANGE FILM";
		  gotoxy(58,14);
		  cout<<"2)DISPLAY FILM";
		  s.display();
		  gotoxy(58,15);
		  cout<<"ANY OTHER TO RETURN";
		  gotoxy(58,16);
		  cout<<"ENTER CHOICE:";
		  cin>>c;
		  }
 
			   switch(c)
			   {
			   case 1: closegraph();
					s.input();
					f.write((char*)&s,sizeof(hall));
					f.close();
					break;
			   case 2: clrscr();
					closegraph();
					f.read((char*)&s,sizeof(hall));
					s.display();
					getch();
					f.close();
					break;
			   case 3: break;
 
			   }
			   break;
 
		  case 2: d=1;
			   while(d==1||d==2||d==3)
			   {
			   closegraph();
			   clrscr();
			   s.f_display();
 
			   gotoxy(58,10);
			   cout<<"RESERVATION";
			   gotoxy(58,11);
			   cout<<"*************";
			   gotoxy(58,13);
			   cout<<"1)FOR BALCONY";
			   gotoxy(58,14);
			   cout<<"2)FOR UPPERSTALL";
			   gotoxy(58,15);
			   cout<<"3)FOR LOWERSTALL";
			   gotoxy(58,16);
			   cout<<"ANY OTHER TO RETURN";
			   gotoxy(58,17);
			   cout<<"ENTER CHOICE:";
			   cin>>d;
			   switch(d);
					{
					case '1':h='y';
						 while(h=='y'||h=='Y')
						 {
						 clrscr();
						 closegraph();
						 //f1.read((char*)&s,sizeof(seats));
						 s.reserve(s.bal);
						 gotoxy(58,16);
						 cout<<"HOW MANY:";
						 cin>>num;
						 s.b_reserve(num);
						 //f1.read((char*)&s,sizeof(seats));
						 s.reserve(s.bal);
						 gotoxy(58,18);
						 cout<<"RESERVE MORE(Y/N):";
						 cin>>h;
						 }
						 closegraph();
						 clrscr();
						 break;
					case '2': h='y';
						 while(h=='y'||h=='Y')
						 {
						 clrscr();
						 closegraph();
						 s.reserve(s.upper);
						 gotoxy(58,16);
						 cout<<"HOW MANY:";
						 cin>>num;
						 s.u_reserve(num);
						 s.reserve(s.upper);
						 gotoxy(58,18);
						 cout<<"RESERVE MORE(Y/N):";
						 cin>>h;
 
						 }
						 closegraph();
						 clrscr();
 
						 break;
					case '3': h='y';
						 while(h=='y'||h=='Y')
						 {
						 clrscr();
						 closegraph();
						 //f1.read((char*)&s,sizeof(seats));
						 s.reserve(s.lower);
						 gotoxy(58,16);
						 cout<<"HOW MANY:";
						 cin>>num;
						 s.l_reserve(num);
						 //f1.read((char*)&s,sizeof(seats));
						 s.reserve(s.lower);
						 gotoxy(58,18);
						 cout<<"RESERVE MORE(Y/N):";
						 cin>>h;
 
						 }
						 closegraph();
						 clrscr();
						 break;
			   }
			   }
			   break;
 
		  case 3 : e=1;
			   while(e==1||e==2||e==3)
			   {
			   closegraph();
			   clrscr();
			   s.f_display();
			   gotoxy(58,10);
			   cout<<"CANCELLATION";
			   gotoxy(58,11);
			   cout<<"*************";
			   gotoxy(58,13);
			   cout<<"1)FOR BALCONY";
			   gotoxy(58,14);
			   cout<<"2)FOR UPPERSTALL";
			   gotoxy(58,15);
			   cout<<"3)FOR LOWERSTALL";
			   gotoxy(58,16);
			   cout<<"ANY OTHYER TO RETURN";
			   gotoxy(58,17);
			   cout<<"ENTER CHOICE:";
			   cin>>e;
			   char m;
			   switch(e)
					{
					case '1': m='y';
						 while(m=='y'||m=='Y')
						 {
						 clrscr();
						 closegraph();
						 //f1.read((char*)&s,sizeof(seats));
						 s.reserve(s.bal);
						 gotoxy(58,16);
						 cout<<"HOW MANY:";
						 cin>>num;
						 s.b_cancel(num);
						 gotoxy(58,18);
						 //f1.read((char*)&s,sizeof(seats));
						 s.reserve(s.bal);
						 cout<<"CANCEL MORE(Y/N):";
						 cin>>m;
						 }
						 closegraph();
						 clrscr();
						 break;
					case '2': m='y';
						 while(m=='y'||m=='Y')
						 {
						 clrscr();
						 closegraph();
						 //f1.read((char*)&s,sizeof(seats));
						 s.reserve(s.upper);
						 gotoxy(58,16);
						 cout<<"HOW MANY:";
						 cin>>num;
						 s.u_cancel(num);
						 //f1.read((char*)&s,sizeof(seats));
						 s.reserve(s.upper);
						 gotoxy(58,18);
						 cout<<"CANCEL MORE(Y/N):";
						 cin>>m;
 
						 }
						 closegraph();
						 clrscr();
 
						 break;
					case '3': m='y';
						 while(m=='y'||m=='Y')
						 {
						 clrscr();
						 closegraph();
						 //f1.read((char*)&s,sizeof(seats));
						 s.reserve(s.lower);
						 gotoxy(58,16);
						 cout<<"HOW MANY:";
						 cin>>num;
						 s.l_cancel(num);
						 //f1.read((char*)&s,sizeof(seats));
						 s.reserve(s.lower);
						 gotoxy(58,18);
						 cout<<"CANCEL MORE(Y/N):";
						 cin>>m;
 
						 }
						 closegraph();
						 clrscr();
						 break;
			   }
			   }
			   break;
		  case 4: closegraph();
				 clrscr();
				 s.f_display();
				 gotoxy(58,10);
				 cout<<"AMOUNT COLECTED:";
				 gotoxy(58,12);
				 cout<<(s.bal*120)+(s.upper*80)+(s.lower*20);
				 getch();
				 closegraph();
				 clrscr();
				 break;
 
		  }
 }
 
 getch();
 
 closegraph();
 }




Is This A Good Question/Topic? 1

Replies To: BGI error: Graphics not initialized (use initgraph)

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: BGI error: Graphics not initialized (use initgraph)

Posted 15 July 2007 - 08:28 AM

Hi, that is a lot of code, so could you tell what is this program for, where do you think the error(the reason for not working) comes from, and so on.
That way you may increase your chances of getting help.
Was This Post Helpful? 0
  • +
  • -

#3 divya272  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 15-July 07

Re: BGI error: Graphics not initialized (use initgraph)

Posted 16 July 2007 - 07:20 AM

View PostPennyBoki, on 15 Jul, 2007 - 08:28 AM, said:

Hi, that is a lot of code, so could you tell what is this program for, where do you think the error(the reason for not working) comes from, and so on.
That way you may increase your chances of getting help.



yeahh the program is for cinema tickets reservation...
i managed to reach the output screen by pressin ALT+F5....an it says....
"BGI error: Graphics not initialized (use initgraph)"
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: BGI error: Graphics not initialized (use initgraph)

Posted 16 July 2007 - 08:18 AM

void graph()
	 {
	 int gdriver=DETECT,gmode;
	 initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
}


What is the intent of the assignment to gdriver? What is the returned value from initgraph()?
Was This Post Helpful? 0
  • +
  • -

#5 dheeraj508  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-January 09

Re: BGI error: Graphics not initialized (use initgraph)

Posted 20 January 2009 - 09:35 AM

can u send me the code for online ticket reservation system for cinema halls in .net

This post has been edited by dheeraj508: 20 January 2009 - 09:36 AM

Was This Post Helpful? 0
  • +
  • -

#6 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: BGI error: Graphics not initialized (use initgraph)

Posted 21 January 2009 - 06:43 AM

I've had people ask me the same question billions of times.
The most probable reason why the program is not working is because your Turbo C++ BGI Graphics folder is not "c:\\tc\\bgi".
Correct the path and it should work.

If you're sure that your path is correct, press Alt+F5 and paste the error received.
Was This Post Helpful? 0
  • +
  • -

#7 chroniko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-March 09

Re: BGI error: Graphics not initialized (use initgraph)

Posted 30 April 2009 - 05:25 PM

Hello, i have a similar problem with the thread starter. I don't have any problems in alt+f5 but when i'm running the program it suddenly closes or crashes. And also i'm used "..\\bgi" since this is also similar as "c:\\tc\\bgi" and also same error if i'm use it vice-versa. Here's my code:


#include <stdio.h>
#include <conio.h>
#include <graphics.h>

int graphdriver=DETECT,graphmode,x;

main()
{
	initgraph (&graphdriver,&graphmode,"..\\bgi");
	clrscr ();

	setcolor (10);settextstyle (0,0,2);
	outtextxy (200,25,"Put Text Here");
	outtextxy (350,25,"Put Text Here");
	circle (120,95,60);setcolor (3);
	for (x=50;x>=0;x--)
	{
		circle (120,95,x);
	}
	setcolor (9);line(200,50,460,50);
	setfillstyle (5,12);bar (200,80,460,150);

getche ();
closegraph();
}


This post has been edited by chroniko: 30 April 2009 - 05:27 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1