Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,674 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,206 people online right now. Registration is fast and FREE... Join Now!




BGI error: Graphics not initialized (use initgraph)

 
Reply to this topicStart new topic

BGI error: Graphics not initialized (use initgraph), this program is compiling without any errors...but is does not run...c

divya272
post 15 Jul, 2007 - 06:49 AM
Post #1


New D.I.C Head

*
Joined: 15 Jul, 2007
Posts: 2


My Contributions


CODE


/*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();
}

User is offlineProfile CardPM

Go to the top of the page

PennyBoki
post 15 Jul, 2007 - 07:28 AM
Post #2


system("revolution");

Group Icon
Joined: 11 Dec, 2006
Posts: 2,009



Thanked 5 times

Dream Kudos: 500

Expert In: Java,C++,C

My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

divya272
post 16 Jul, 2007 - 06:20 AM
Post #3


New D.I.C Head

*
Joined: 15 Jul, 2007
Posts: 2


My Contributions


QUOTE(PennyBoki @ 15 Jul, 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.



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)"
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 16 Jul, 2007 - 07:18 AM
Post #4


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,178



Thanked 33 times

Dream Kudos: 25
My Contributions


CODE

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()?
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 06:25AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month