TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ken H
NA
646
360.7k
custom console menu in c++
Oct 16 2013 3:14 AM
Hello everyone,
My question is:Arrow pointing to an invalid area.Details can be viewed in the attachment to the operation of the demonstration.
my code is as follows:
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
/* direction keys */
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77
static int POINTER_TO_ROW=0;
static int POINTER_TO_COLUMN=0;
const string menu_name[4][4]={"Menu1","Menu2","Menu3","Menu4","Menu5","Menu6","Menu7","Menu8"};
string menu_name_t[4][4]={"Menu1","Menu2","Menu3","Menu4","Menu5","Menu6","Menu7","Menu8"};
const string flag="->";
int i=0,j=0,k=0,newline=0;
/* Function prototypes */
void menu();
void reset_menu_name_t();
int main()
{
char Key='Y';
menu();
system("color 16"); /* Setting up the console background and foreground colors */
while (toupper(Key)!='N')
{
Key=getch(); /* get current direction keys */
switch(Key)
{
case 72: /* UP */
system("cls");
POINTER_TO_ROW--;
menu();
break;
case 80: /* DOWN */
system("cls");
POINTER_TO_ROW++;
menu();
break;
case 75: /* LEFT */
/**/
break;
case 77: /* RIGHT */
/**/
break;
}
}
return 0;
}
void reset_menu_name_t()
{
for(j=0;j<4;j++)
{
for (k=0;k<4;k++)
{
menu_name_t[j][k]="";
menu_name_t[j][k]=menu_name[j][k];
}
}
}
void menu()
{
if(POINTER_TO_ROW>3) POINTER_TO_ROW=0;
if(POINTER_TO_ROW<0) POINTER_TO_ROW=3;
menu_name_t[POINTER_TO_ROW][POINTER_TO_COLUMN]=flag+menu_name_t[POINTER_TO_ROW][POINTER_TO_COLUMN];
cout<<"\n\n\n\n";
newline=0;
for (i=0;i<4;i++)
{
for (k=0;k<4;k++)
{
if(newline%2==0) cout<<"\n";
if(i==POINTER_TO_ROW&&k==POINTER_TO_COLUMN)cout<<"\t\b\b"<<menu_name_t[i][k]<<"\t";
else cout<<"\t"<<menu_name_t[i][k]<<"\t";
newline++;
}
}
cout<<"\n\n\tEnter N to exit program."<<'\n';
reset_menu_name_t();
}
Regards,
Ken
thank very much. :)
Attachment:
menu.rar
Reply
Answers (
2
)
use + for string concatenation in c++
Uncertain parameters in C