1 Replies - 4694 Views - Last Post: 07 December 2010 - 05:38 PM Rate Topic: -----

#1 Ashu2912  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 03-November 10

settextstyle in c++

Posted 07 December 2010 - 12:24 AM

Hey friends, I have written down a long code for my project, but the settextstyle function in the 'exit_prog' function is not showing the expected output. I have indicated the line with a comment. Please help me as fast as you can :

void disptime ()       //Function to display the time on the upper
{                      //right corner of the screen.
     time_t t1;
     time (&t1);
     tm * t2;
     t2 = localtime (&t1);
     gotoxy (57, 1);
     textcolor (6);
     cprintf ("%s", asctime (t2));
     textcolor (YELLOW);
}

void exit_prog ()       //To exit from the program.
{
     int gd, gm;
     detectgraph (&gd, &gm);
     initgraph (&gd, &gm, "C:\\TC\\BIN");
     setbkcolor (6);
     settextstyle (4, 0, 5);  //THIS FUNCTION NOT GIVING EXPECTED OUTPUT.
     setcolor (15);
     moveto (9,5);
     outtext ("thanx");
     getch ();
     exit (1);
}

void password ()      //To input the password for using the program.
{
     int n;
     char pass [5];
     int gd, gm;
     detectgraph (&gd, &gm);      //Initializing graphics mode.
     initgraph (&gd, &gm, "C:\\TC\\BGI");
     setbkcolor (1);
     setcolor (15);
     settextjustify (1,1);
     for (int i = 1; i <= 5; i ++)      //Maximum of 5 attempts given.
     {
	 cleardevice ();
	 settextstyle (4,0,3);
	 outtextxy (getmaxx () / 2 + 20, getmaxy () / 2 - 135, "A.S.M. Groups");
	 settextstyle (7,0,5);
	 outtextxy (getmaxx () / 2, getmaxy () / 2 - 40, "iGAME GAMING ARENA");
	 line (0, 165, getmaxx (), 165);
	 line (0, 255, getmaxx (), 255);
	 settextstyle (4,0,3);
	 outtextxy (getmaxx () - 375, getmaxy () - 175, "Enter the password here :- ");
	 for (int j = 0; j <= 19; j ++)    //Taking password input into a string.
	 {
	     moveto (getmaxx () - 200 - j + (j * 12), getmaxy () - 175);
	     n = getch ();
	     if (n == '\r')   //If 'Enter' pressed, input stops.
		break;
	     pass [j] = n;
	     outtextxy (getmaxx () - 200 - j + (j * 12), getmaxy () - 175, "*");
	     //'*' printed after going back to the place of the character.
	 }
	 pass [j] = '\0';
	 if (!strcmp (pass, "admin"))
	    return;
	 else
	 {
	    if (i == 5)  //All 5 attempts used up.
	    {
	       outtextxy (getmaxx () - 310, getmaxy () - 120, "You have entered the incorrect password for five times in");
	       outtextxy (getmaxx () - 300, getmaxy () - 80, "a row. Aborting!!!");
	       getch ();
	       exit_prog ();    //Exit screen shown.
	    }
	    outtextxy (getmaxx () - 300, getmaxy () - 120, "You have entered an invalid password. Please try again...");
	    getch ();
	 }
     }
     restorecrtmode ();
}

void welcome ()     //To display the welcome screen to the user if he enters
{                   //the correct password.
     int gd, gm;
     detectgraph (&gd, &gm);     //Initializing graphics mode.
     initgraph (&gd, &gm, "C:\\TC\\BGI");
     cleardevice ();
     disptime ();
     setbkcolor (1);
     setcolor (15);
     settextjustify (1,1);
     settextstyle (4,0,5);
     outtextxy (getmaxx () / 2 + 30, getmaxy () / 2 - 180, "Welcome to");
     settextstyle (4,0,3);
     outtextxy (getmaxx () / 2 + 30, getmaxy () / 2 - 115, "A.S.M. Groups");
     settextstyle (7,0,5);
     outtextxy (getmaxx () / 2, getmaxy () / 2 - 40, "iGAME GAMING ARENA");
     line (0, 165, getmaxx (), 165);
     line (0, 255, getmaxx (), 255);
     settextstyle (4,0,3);
     outtextxy (getmaxx () - 300, getmaxy () - 180, "System.");
     outtextxy (getmaxx () - 300, getmaxy () - 150, "You are currently logged into the system as User1!!!");
     outtextxy (getmaxx () - 293, getmaxy () - 115, "Press any key to continue.....");
     getch ();
     restorecrtmode ();
}
...
...
...
...
...
...
...
void main ()
{
     void password ();
     void welcome ();
     void menu1 ();
     //void show ();
     void exit_prog ();
     password ();  //If correct password entered, then control reaches here.
     welcome ();
     menu1 ();
     exit_prog ();
     //show ();
}



Is This A Good Question/Topic? 0
  • +

Replies To: settextstyle in c++

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1344
  • View blog
  • Posts: 4,606
  • Joined: 19-February 09

Re: settextstyle in c++

Posted 07 December 2010 - 05:38 PM

I think you only need to detectgraph() and initgraph() once in the program.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1