Can you post a complete program that shows the problem?
Ok, but it's little big! You'll need to include two header files.
Make a folder called header_files and then put two header files in it
called pretty_code.h and cursor.h respectively:
Anyways, here is the code:
-------------------------------
header_files/pretty_code.h
-------------------------------
#ifndef pretty_code_h
#define pretty_code_h
#include <iomanip>
#include <iostream>
#include "cursor.h"
using namespace std;
// begin code:
void header(bool clear_screen, string text, string table_type, string
table_filler, int cols_across, int rows_down)
{
if(clear_screen == true)
{
system("CLS");
}
// table text variables.
int top_left_corner = 0;
int top_right_corner = 0;
int horizontal_line = 0;
int vertical_line = 0;
int bottom_left_corner = 0;
int bottom_right_corner = 0;
if(table_type == "single")
{
top_left_corner = 218;
top_right_corner = 191;
horizontal_line = 196;
vertical_line = 179;
bottom_left_corner = 192;
bottom_right_corner = 217;
}
else if(table_type == "double")
{
top_left_corner = 201;
top_right_corner = 187;
horizontal_line = 205;
vertical_line = 186;
bottom_left_corner = 200;
bottom_right_corner = 188;
}
int string_length = text.length();
int cell_internal_fill = 0;
if(table_filler == "blank") cell_internal_fill = 0;
else if(table_filler == "dots") cell_internal_fill = 46;
else if(table_filler == "white") cell_internal_fill = 219;
else if(table_filler == "music") cell_internal_fill = 14;
else if(table_filler == "matrix") cell_internal_fill = 177;
else if(table_filler == "hearts") cell_internal_fill = 3;
else if(table_filler == "zigzag1") cell_internal_fill = 176;
else if(table_filler == "zigzag2") cell_internal_fill = 178;
else if(table_filler == "diamonds") cell_internal_fill = 4;
gotoxy(cols_across, rows_down);
cout << char(top_left_corner);
for(int i = 0; i < string_length + 6; i++)
{
cout << char(horizontal_line);
}
cout << char(top_right_corner);
gotoxy(cols_across, rows_down + 1);
cout << char(vertical_line);
cout << setfill(char(cell_internal_fill));
cout << setw(string_length + 7);
cout << char(vertical_line);
gotoxy(cols_across, rows_down + 2);
cout << char(vertical_line);
for(int i = 0; i < 3; i++)
cout << char(cell_internal_fill);
cout << text ;
for(int i = 0; i < 3; i++)
cout << char(cell_internal_fill);
cout << char(vertical_line);
gotoxy(cols_across, rows_down + 3);
cout << char(vertical_line);
cout << setfill(char(cell_internal_fill));
cout << setw(string_length + 7);
cout << char(vertical_line);
gotoxy(cols_across, rows_down + 4);
cout << char(bottom_left_corner);
for(int i = 0; i < string_length + 6; i++)
{
cout << char(horizontal_line);
}
cout << char(bottom_right_corner);
}
// :end code
#endif
-------------------------------
header_files/cursor.h
-------------------------------
#ifndef cursorh
#define cursorh
#include<iostream>
#include<windows.h>
//Redifine functions that could clash with conio.h
#define clrscr cursorh_clrscr
#define gotoxy cursorh_gotoxy
#define wherex cursorh_wherex
#define wherey cursorh_wherey
using namespace std;
HANDLE cursorhConsoleOut = GetStdHandle( STD_OUTPUT_HANDLE );
HANDLE cursorhConsoleIn = GetStdHandle( STD_INPUT_HANDLE );
CONSOLE_SCREEN_BUFFER_INFO cursorhScreen_info;
DWORD cursorhConModeNum = ENABLE_WINDOW_INPUT|ENABLE_MOUSE_INPUT;
static int cursorhFOREGROUND = 15;//Bright white
static int cursorhBACKGROUND = 0;//Black
static int cursorhOLDFOREGROUND = 15;
static int cursorhOLDBACKGROUND = 0;
inline void gotoXY(int x, int y)
{
cout << flush;
GetConsoleScreenBufferInfo
(cursorhConsoleOut,&cursorhScreen_info);
cursorhScreen_info.dwCursorPosition.Y = y;
cursorhScreen_info.dwCursorPosition.X = x;
SetConsoleCursorPosition
(cursorhConsoleOut,cursorhScreen_info.dwCursorPosition);
}
inline void cursorh_gotoxy( int x, int y)
{
gotoXY(x, y);
}
inline int whereX()
{
GetConsoleScreenBufferInfo(cursorhConsoleOut, &cursorhScreen_info);
return cursorhScreen_info.dwCursorPosition.X;
}
inline int whereY()
{
GetConsoleScreenBufferInfo(cursorhConsoleOut, &cursorhScreen_info);
return cursorhScreen_info.dwCursorPosition.Y;
}
inline int cursorh_wherex()
{
return whereX();
}
inline int cursorh_wherey()
{
return whereY();
}
inline void where_mouse(int & x, int & y)
{
INPUT_RECORD event_info;
MOUSE_EVENT_RECORD mouse_info;
DWORD oldConsoleMode;
GetConsoleMode(cursorhConsoleIn,&oldConsoleMode);
SetConsoleMode(cursorhConsoleIn,cursorhConModeNum);
DWORD count;
while(true)
{
if(ReadConsoleInput(cursorhConsoleIn, &event_info, 1, &count))
{
if(event_info.EventType == MOUSE_EVENT)
{
mouse_info = event_info.Event.MouseEvent;
if(mouse_info.dwEventFlags == 0)
{
break;
}
}
}
Sleep(100);
}
x = mouse_info.dwMousePosition.X;
y = mouse_info.dwMousePosition.Y;
SetConsoleMode(cursorhConsoleIn,oldConsoleMode);
}
//////////////////////////////clrscr()///////////////////////////
//// called cursor_clrscr() to distinguish between it and one
//// that might be in conio.h
//// This one uses the present colors to fill the screen. If you
//// want the old colors, use resetcolors() first.
///////////////////////////////////////////////////////////////
inline void cursorh_clrscr()
{
GetConsoleScreenBufferInfo(cursorhConsoleOut,
&cursorhScreen_info);
DWORD written;
int x = cursorhScreen_info.dwSize.X;
int y = cursorhScreen_info.dwSize.Y;
int z = x * y;
COORD top_left;
top_left.X = 0;
top_left.Y = 0;
FillConsoleOutputAttribute (cursorhConsoleOut,
cursorhFOREGROUND|cursorhBACKGROUND,
z,
top_left,
&written);
FillConsoleOutputCharacter (cursorhConsoleOut,
' ',
z,
top_left,
&written);
cursorhOLDFOREGROUND = cursorhFOREGROUND;
cursorhOLDBACKGROUND = cursorhBACKGROUND;
gotoXY (0, 0);
}
//////////////////////////////// setbackgroundcolor
() /////////////////////
////// Use all or any of:-
// BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|
BACKGROUND_INTENSITY
///// as colors inside the brackets
//// e.g for bright yellow use
//// setbackgroundcolor( BACKGROUND_RED|BACKGROUND_GREEN|
BACKGROUND_INTENSITY);
//// for bright cyan use
//// setbackgroundcolor( BACKGROUND_BLUE|BACKGROUND_GREEN|
BACKGROUND_INTENSITY);
//// for bright magenta use
//// setbackgroundcolor( BACKGROUND_RED|BACKGROUND_BLUE|
BACKGROUND_INTENSITY);
//// for black use
//// setbackgroundcolor(0);
/// for bright white use
//// setbackgroundcolor( BACKGROUND_RED
// |BACKGROUND_GREEN
// |BACKGROUND_BLUE
// |BACKGROUND_INTENSITY);
//////////////////////////////////////////////////////////////////////
inline void
setbackgroundcolor(int color)
{
SetConsoleTextAttribute (cursorhConsoleOut, cursorhFOREGROUND|
color);
cursorhBACKGROUND = color;
}
//////////////////////////////// settextcolor() /////////////////////
////// Use all or any of:-
// FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|
FOREGROUND_INTENSITY
///// as colors inside the brackets
//// e.g for bright yellow use
//// settextcolor( FOREGROUND_RED|FOREGROUND_GREEN|
FOREGROUND_INTENSITY);
//// for bright cyan use
//// settextcolor( FOREGROUND_BLUE|FOREGROUND_GREEN|
FOREGROUND_INTENSITY);
//// for bright magenta use
//// settextcolor( FOREGROUND_RED|FOREGROUND_BLUE|
FOREGROUND_INTENSITY);
//// for black use
//// settextcolor(0);
/// for bright white use
//// settextcolor( FOREGROUND_RED
// |FOREGROUND_GREEN
// |FOREGROUND_BLUE
// |FOREGROUND_INTENSITY);
//////////////////////////////////////////////////////////////////////
inline void
settextcolor(int color)
{
SetConsoleTextAttribute (cursorhConsoleOut, cursorhBACKGROUND|color);
cursorhFOREGROUND = color;
}
inline void
resetcolors()
{
settextcolor(cursorhOLDFOREGROUND);
setbackgroundcolor(cursorhOLDBACKGROUND);
cursorhBACKGROUND = cursorhOLDBACKGROUND;
cursorhFOREGROUND = cursorhOLDFOREGROUND;
}
#endif
-------------------------------
main code file
-------------------------------
#include <iostream>
#include <iomanip>
#include "header_files/pretty_code.h"
#include "header_files/cursor.h"
using namespace std;
// structures:
struct DVD
{
int id_number;
char title[50];
char production_company[20];
char censor_rating[3];
char category[20];
char rental_period[2];
};
// functions:
// Console user interface screens (procedures):
// note: the procedures are listed in the same order as their
prototypes.
void main_screen(void);
void dvd_database_screen(void);
void add_dvd_screen();
void remove_dvd_screen();
void customer_database_screen(void);
void dvd_loan_screen(void);
void exit_program_screen(void);
int main()
{
main_screen();
cout << "\nbroken out from main screen!\n";
cin.get();
cin.get();
}
// main screen
void main_screen(void)
{
// display heading
header(true," ", "double", "matrix", 25, 1);
// list choices capable of being made
int x = 7;
gotoxy(25, x);
cout << " 1 " << char(16) << " DVD Database";
gotoxy(25, x+=2);
cout << " 2 " << char(16) << " Customer Database";
gotoxy(25, x+=2);
cout << " 3 " << char(16) << " DVD Loan";
gotoxy(25, x+=2);
cout << " 0 " << char(16) << " Exit Program";
// ask user for their choice
gotoxy(25,x+=2);
cout << "Choice: ";
int choice = 0;
cin >> choice;
// react to their choice
switch(choice)
{
case 1 : {
dvd_database_screen();
}
break;
case 2 : {
customer_database_screen();
}
break;
case 3 : {
dvd_loan_screen();
}
break;
case 0 : {
exit_program_screen();
}
break;
default: {
gotoxy(25, x+=2);
cout << "Choice " << choice << " does not exist.";
gotoxy(25, x+=1);
cout << "Press Enter and re-enter your choice.";
cin.get();
cin.get();
main_screen();
}
}
}
void dvd_database_screen()
{
header(true," DVD Database ", "double", "matrix", 25,
1);
int x = 7;
gotoxy(25, x);
cout << " 1 " << char(16) << " Add DVD";
gotoxy(25, x+=2);
cout << " 2 " << char(16) << " Remove DVD";
gotoxy(25,x+=2);
cout << "Choice: ";
int choice = 0;
cin >> choice;
if(1 == choice)
{
add_dvd_screen();
}
else if(2 == choice)
{
remove_dvd_screen();
}
else
{
gotoxy(25, x+=2);
cout << "Choice " << choice << " does not exist.";
gotoxy(25, x+=1);
cout << "Press Enter and re-enter your choice.";
cin.get();
cin.get();
main_screen();
}
}
void add_dvd_screen()
{
header(true," Add DVD ", "double", "matrix", 25, 1);
int x = 7;
DVD newDVD;
gotoxy(25, x);
cout << "DVD Title: ";
cin.ignore(2);
cin.getline(newDVD.title,50);
header(true," Add DVD ", "double", "matrix", 25, 1);
gotoxy(25, x);
cout << "DVD Production Company: ";
string production_companies[9] = {
"Paramount Pictures",
"Sony Entertainment",
"Fox Entertainment",
"Universal Studios",
"NBC Universal",
"Walt Disney",
"Time Warner",
"Dreamworks",
"Lionsgate",
};
int y = x;
for(int i = 0; i < 9; i++)
{
gotoxy(25, y+=2);
cout << i << " = " << production_companies
;
}
gotoxy(25, y+=2);
int production_company_choice = -1;
cout << "Choice : ";
cin >> production_company_choice;
cin.ignore();
if(production_company_choice > 8 ||
production_company_choice < 0)
{
gotoxy(25, y+=2);
cout << "Choice " << production_company_choice << "
does not exist.";
gotoxy(25, y+=1);
cout << "Press Enter and re-enter your choice.";
cin.get();
add_dvd_screen();
}
else
{
for(int i = 0; i < 20; i++)
{
newDVD.production_company = production_companies
[production_company_choice].at(i);
}
}
cin.ignore();
cout << endl << newDVD.production_company << endl;
cin.get();
cin.get();
//header(true," Add DVD ", "double", "matrix", 25, 1);
gotoxy(25, x);
cout << "DVD Classification: ";
cin >> newDVD.censor_rating;
//header(true," Add DVD ", "double", "matrix", 25, 1);
gotoxy(25, x);
cout << "DVD Category: ";
cin >> newDVD.category;
//header(true," Add DVD ", "double", "matrix", 25, 1);
gotoxy(25, x);
cout << "DVD Rental Period: ";
cin >> newDVD.rental_period;
cin.get();
cin.get();
}
void remove_dvd_screen()
{
header(true," Remove DVD ", "double", "matrix", 25, 1);
cin.get();
cin.get();
}
void customer_database_screen()
{
}
void dvd_loan_screen()
{
}
void exit_program_screen()
{
header(true," Exit Program? ", "double", "matrix", 25, 1);
int x = 7;
gotoxy(25, x);
cout << " 1 " << char(16) << " Yes";
gotoxy(25, x+=2);
cout << " 2 " << char(16) << " No";
gotoxy(25,x+=2);
cout << "Choice: ";
int choice = 0;
cin >> choice;
if(1 == choice)
{
exit(1);
}
else if(2 == choice)
{
main_screen();
}
else
{
gotoxy(25, x+=2);
cout << "Choice " << choice << " does not exist.";
gotoxy(25, x+=1);
cout << "Press Enter and re-enter your choice.";
cin.get();
cin.get();
exit_program_screen();
}
}