Firstly, i press ENTER to exit the 1st do..while loop
and then the programe ask Rent Paid(y/n):
if i press n and then ENTER,
the program return rent_step2,
and it is supposed to wait for me before i press ENTER again


But it just break the 1st do..while loop and not waiting for me pressing ENTER
it skips to ask Rent Paid(y/n):

so how can i solve this problem....

I have also uploaded all of the source code

void rent_locker(){

rent_step1:
           //................
rent_step2:

   do{
       if(GetAsyncKeyState(VK_UP) != 0){
           //................
       }else if(GetAsyncKeyState(VK_DOWN) != 0){
           //................
       }else if(GetAsyncKeyState(VK_LEFT) != 0){
           //................
       }else if(GetAsyncKeyState(VK_RIGHT) != 0){
           //................
       }else if(GetAsyncKeyState(8) != 0){
           goto rent_step1;
       }
           //................
	   Sleep(300);
   }while(!(GetAsyncKeyState(13)));

rent_step3: 
   char confirm[10];
   confirm[0]='u';
   do{
      cout << "Rent Paid(y/n): ";
      cin >> confirm;
   }while(strlen(confirm)>1 || !(confirm[0]=='y'||confirm[0]=='Y'||
			      confirm[0]=='n'||confirm[0]=='N'));  
   
   if(confirm[0]=='y' || confirm[0]=='Y'){
	   cout << "*** PAID!!! ***";
   }else if(confirm[0]=='n' || confirm[0]=='N'){
	   confirm[0]='u';
	   goto rent_step2;
   }
   system("pause");
   return;
}
Attachments
#include <iostream>
#include <windows.h>
#include <string>
#include <cmath>
#include <limits>

using namespace std;

char locker_frame[9][77] = {"+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Locker   |  |  |  |  |  |  |  |  |  |  |  |",
		                    "+--+--+--+--+--+--+--+--+--+--+           +--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Control  |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+           +--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Panel    |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+"};

string locker_data[4][4][25];

static HANDLE hOut;
int clicked;

#define FW  FOREGROUND_RED |\
            FOREGROUND_GREEN |\
            FOREGROUND_BLUE

void gotoxy(unsigned short x, unsigned short y);
void rent_locker();
void cancel_locker();
void admin_mode();
void draw_locker(int location);
void initialize_locker_data();
void highlight(int x_coor1, int y_coor1,int x_coor2,int y_coor2, int color);
int check_available(int location,int row,int col);
int locker_remain(int location,int row,int col,int direction);

void main(){

	//do{
	//	system("cls");
	//	gotoxy(0,0);
	//	cout << "    " << GetAsyncKeyState(13) << "    ";
	//}while(2>1);


    SetConsoleTitle("Locker Rental System");
    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
	initialize_locker_data();
main_menu:
    system("cls");
    char menu_option[3][30]={"1)Rent a locker\n",
		                     "2)Cancel a locker rental\n",
                             "3)Administrator mode\n"};

	cout << "Please Select an Option\n";
	cout << "     ==>" << menu_option[0];
	cout << "        " << menu_option[1];
	cout << "        " << menu_option[2];

	int key=1;
	do{
        if(GetAsyncKeyState(VK_UP) != 0){
            if(key>1){key-=1;}
        }else if(GetAsyncKeyState(VK_DOWN) != 0){
            if(key<3){key+=1;}
        }
		if(key!=1){
			gotoxy(0,key-1);
			cout << "        ";
                               SetConsoleTextAttribute(hOut,FW | 0);
			                   cout << menu_option[key-2];
		}
		if(key!=3){
			gotoxy(0,key+1);
			cout << "        ";
                               SetConsoleTextAttribute(hOut,FW | 0);
			                   cout << menu_option[key];
		}
		gotoxy(0,key);
		cout << "     ==>";
                           SetConsoleTextAttribute(hOut,BACKGROUND_GREEN |BACKGROUND_INTENSITY);
	                       cout << menu_option[key-1];
                           SetConsoleTextAttribute(hOut,FW | 0);
	
		Sleep(200);
	}while(!GetAsyncKeyState(13));

    switch(key){
	      case 1: rent_locker();
			      break;
		  case 2: cancel_locker();
			      break;
		  case 3: admin_mode();
	}

    goto main_menu;
}

void gotoxy(unsigned short x, unsigned short y)
{
    COORD WritePos;
    WritePos.X = x; 
    WritePos.Y = y;
    SetConsoleCursorPosition(hOut,WritePos);
}

void rent_locker(){
	char building[8][30]={"_____________________________",
		                  "|        Second Floor       |",
						  "_____________________________",
		                  "|        First Floor        |",
						  "_____________________________",
		                  "|     Ground Floor Shops    |",
						  "_____________________________",
						  "|     Basement Car Park     |"};

   int stack_no=0;

rent_step1:
   system("cls");

   cout << "Step 1: Please select a locker stack location:\n";

   for(int i=0;i<8;i++){cout << "        " << building[i] << endl;}

   cout << "\nPress \"Back Space\" to return previous page";

   clicked=1;
   do{
       if(GetAsyncKeyState(VK_UP) != 0){
           if(stack_no>0){
			   stack_no-=1;
			   clicked=1;
		   }
       }else if(GetAsyncKeyState(VK_DOWN) != 0){
           if(stack_no<3){
			   stack_no+=1;
			   clicked=1;
		   }
       }else if(GetAsyncKeyState(8) != 0){
           return;
	   }

	   if(clicked==1){
          if(stack_no!=0){
		     gotoxy(0,stack_no*2-1);
		     cout << "        ";
                                SetConsoleTextAttribute(hOut,FW | 0);
			                    cout << building[stack_no*2-2] << endl;
             cout << "        "  << building[stack_no*2-1] << endl;
		                      
		  }
	      if(stack_no!=3){
		     gotoxy(0,stack_no*2+3);
		     cout << "        ";
                                SetConsoleTextAttribute(hOut,FW | 0);
			                    cout << building[stack_no*2+2] << endl;
             cout << "        "  << building[stack_no*2+3] << endl;
		  }
	      gotoxy(0,stack_no*2+1);
	      cout << "        " << building[stack_no*2] << endl;
          cout << "     ==>" << building[stack_no*2+1] << endl;

          highlight(8,stack_no*2+1,36,stack_no*2+2,BACKGROUND_GREEN |BACKGROUND_INTENSITY);

		  clicked=0;
	   }

	   Sleep(200);
	   gotoxy(0,0);
   }while(!GetAsyncKeyState(13));

rent_step2:
   system("cls");
   string location_name;

   switch(stack_no){
        case 3:location_name="Basement Car Park";
			   break;
		case 2:location_name="Ground Floor Shops";
			   break;
		case 1:location_name="First Floor";
			   break;
		case 0:location_name="Second Floor";
   }


   cout << "Locker Stack Location no. " << abs(stack_no-4) << " - " << location_name << endl;
   cout << "Daily charges: Top=$20, Bottom=$10, The Rest=$15\n\n";  
   
   draw_locker(stack_no);
   
   gotoxy(0,13);
   cout << "Press \"Back Space\" to return previous page";

   int x_position=0,y_position=0;
   
   for(i=0;i<4;i++){
	   for(int j=0;j<25;j++){
		   if(check_available(stack_no,i,j)==1){
			   x_position=j;
			   y_position=i;
			   break;
		   }
	   }
	   if(x_position!=0 || y_position !=0 || check_available(stack_no,0,0) == 1){break;}
       if(check_available(stack_no,0,0) == 0 && x_position == 0 && y_position == 0 ){
		   system("cls");
		   cout << "The Lockers in this location are full\n";
		   Sleep(3000);
		   goto rent_step1;
	   }
   }

   clicked=1;
   do{
       if(GetAsyncKeyState(VK_UP) != 0){
           if(locker_remain(stack_no,y_position,x_position,0) != -1){
			  highlight(x_position*3,y_position*2+3,
			            x_position*3+3,y_position*2+5,
					    FW | 0);
              y_position=locker_remain(stack_no,y_position,x_position,0);
			  clicked=1;
		   }
       }else if(GetAsyncKeyState(VK_DOWN) != 0){
           if(locker_remain(stack_no,y_position,x_position,1) != -1){
			  highlight(x_position*3,y_position*2+3,
			            x_position*3+3,y_position*2+5,
					    FW | 0);
              y_position=locker_remain(stack_no,y_position,x_position,1);
			  clicked=1;
		   }
       }else if(GetAsyncKeyState(VK_LEFT) != 0){
           if(locker_remain(stack_no,y_position,x_position,2) != -1){
			  highlight(x_position*3,y_position*2+3,
			            x_position*3+3,y_position*2+5,
					    FW | 0);
              x_position=locker_remain(stack_no,y_position,x_position,2);
			  clicked=1;
		   }
       }else if(GetAsyncKeyState(VK_RIGHT) != 0){
           if(locker_remain(stack_no,y_position,x_position,3) != -1){
			  highlight(x_position*3,y_position*2+3,
			            x_position*3+3,y_position*2+5,
					    FW | 0);
              x_position=locker_remain(stack_no,y_position,x_position,3);
			  clicked=1;
		   }
       }else if(GetAsyncKeyState(8) != 0){
           goto rent_step1;
	   }

	   if(clicked==1){
		   highlight(x_position*3,y_position*2+3,
			         x_position*3+3,y_position*2+5,
					 BACKGROUND_GREEN |BACKGROUND_INTENSITY);
		   clicked=0;
	   }

	   gotoxy(59,0);
	   string rental_price (locker_data[stack_no][y_position][x_position],2,2); 
       cout << "Rental Price: ";
       SetConsoleTextAttribute(hOut,FOREGROUND_RED | 
                                    FOREGROUND_GREEN |
									FOREGROUND_INTENSITY);
	   cout << "$" << rental_price;
	   SetConsoleTextAttribute(hOut,FW |0);

       gotoxy(0,0);
	   Sleep(300);
   }while(!(GetAsyncKeyState(13)));// & 0x8000;

rent_step3: 
   gotoxy(0,16);
   string rental_price (locker_data[stack_no][y_position][x_position],2,2); 
   cout << "The rental price is $" << rental_price << endl;
   
   fflush(stdin);
   char confirm[10];
   confirm[0]='u';
   do{
      cout << "Rent Paid(y/n): "<< flush;
	  fflush(stdin);
      cin.clear();
      cin >> confirm;
   }while(strlen(confirm)>1 || !(confirm[0]=='y'||confirm[0]=='Y'||
			                     confirm[0]=='n'||confirm[0]=='N'));  

   fflush(stdin);
   if(confirm[0]=='y' || confirm[0]=='Y'){
	   confirm[0]='u';
	   cout << "*** PAID!!! ***";
   }else if(confirm[0]=='n' || confirm[0]=='N'){
	   confirm[0]='u';
	   goto rent_step2;
   }
 
   return;
}

void cancel_locker(){
	system("cls");
    return;
}

void admin_mode(){
    system("cls");
	return;
}

void draw_locker(int location){
     int i,j,k;
     char temp_locker_frame[9][77];

     for(i=0;i<9;i++){
        for(j=0;j<77;j++){
		   temp_locker_frame[i][j]=locker_frame[i][j];
		}
	 }

	 for(j=0;j<4;j++){
		for(k=0;k<25;k++){
			string available (locker_data[location][j][k],0,1); 
            if(available=="n"){
			   	temp_locker_frame[j*2+1][k*3+1]='X';
				temp_locker_frame[j*2+1][k*3+2]='X';
			}
		}
	 }

     for(i=0;i<9;i++){
		 for(j=0;j<77;j++){
			 if(temp_locker_frame[i][j]=='X'){
				 SetConsoleTextAttribute(hOut,FOREGROUND_RED |FOREGROUND_INTENSITY);
                 cout << temp_locker_frame[i][j];
                 SetConsoleTextAttribute(hOut,FW | 0);
			 }else{
				 cout << temp_locker_frame[i][j];
			 }
		 }
		 cout << endl;
	 }

}

void initialize_locker_d

Well first off main() cannot be void... it must return int... so I changed it to

int main()       //changed void main() to int main()
{
  .............
}

Also the code below needs redeclaration of i
cuz its declared in the first for statement and it is not in scope in the second for statement. you gotta declare another variable for the second for statement.
See i isnt declared outside the first loop and is fixed below..

for(i=0;i<4;i++;){                                              // your also missing ;  which was fixed after the j++ and before the )
	   for(int j=0;j<25;j++){
		   if(check_available(stack_no,[b]i=0[/b],j)==1){                            // Changed i to i=0
			   x_position=j;
			   y_position=i;
			   break;
		   }
	   }

OR u can do the following:

int i=0;       // Put "i" outside the scope of the for function so it is defined for all functions below
   for(i<4;i++){
	   for(int j=0;j<25;j++){
		   if(check_available(stack_no,i,j)==1){
			   x_position=j;
			   y_position=i;
			   break;
		   }
	   }

As for getasynckey.. cant u just do:

if(keybd_event(VK_RETURN, 0, 0, 0); keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);)
{
      //code
}

Not sure if the above will work...

but Im trying to fix it right now... hopefully I come up with a solution... btw in other compilers, putting the variable inside the scope like that is illegal... microsoft's compiler for some reason accepts this and says its appropriate...

Edited 6 Years Ago by triumphost: n/a

Due to not being able to edit previous posts after 30 mins, i posted the following below...

rent_step3: 
   gotoxy(0,16);
   string rental_price (locker_data[stack_no][y_position][x_position],2,2); 
   cout << "The rental price is $" << rental_price << endl;
   
   fflush(stdin);
   char confirm[10];
   confirm[0]='u';
   do{
      cout << "Rent Paid(y/n): "<< flush;
	  fflush(stdin);
      cin.clear();
      cin >> confirm;
   }while(strlen(confirm)>1 || !(confirm[0]=='y'||confirm[0]=='Y'||
			                     confirm[0]=='n'||confirm[0]=='N'));  

   fflush(stdin);
   if(confirm[0]=='y' || confirm[0]=='Y'){
	   confirm[0]='u';
	   cout << "*** PAID!!! ***";
	   cin.get();                                  //Notice the cin.get(); That waits for u to press enter and then it does not go back to rent a locker but rather it goes back to the floor selection menu because of your return command... aka going back to

void rent_locker();

I just noticed ur problem is when u press no and it skips asking u to choose a floor... this is because the memory is not cleared and it keeps that choice stored... stack_no still has the value stored from the previous time that u chose the locker... so u need to clear stack_no so that it allows u to choose which floor u want.. I will try n see if I can do that with all these goto's everywhere but I had that problem yesterday and solved it.... my solution was to remove goto commands as they do not deconstruct properly... rather they skip over all the code and jumps to a specified point in the program... this leaves all that stuff in the memory and doesnt clear it... at least thats what I read on the stackoverflow website last night.. i solved it by making everything a function and whenever I wanted the program to get back to the start or a specific point id just call that function

Example:

#include <iostream>
#include <windows.h>

int x;

using namespace std;

void menu();   // declares the prototype function - menu(); before it is used...
void stuff();
void rent();
void cancel();
void admin();
void tryagain();


int main()
{
   menu();
return 0;
}

void menu()
{
  cout<<"rent a locker\n";
   cout<<"cancel locker renting\n";
   cout<<"admin mode\n";
   stuff();
}
void stuff()
{
  cin>>x;
  cin.ignore();
  switch(x)
  {
    case '1': rent();
            break;
    case '2': cancel();
            break;
    case '3': admin();
            break;
    default: cout<<"That option is not in the menu, try again\n";
             menu();
             break;
   }
}
void rent()
{
  //do stuff
}
void cancel()
{
  //do stuff
}
void admin()
{
  //do stuff
}

notice I didnt say goto menu(); for the default... because if I did, it will not deconstruct stuff() properly and will give me an infinite loop kinda like what u have... the options will definitely stay there rather than being removed from the memory... I dont know exactly how else to clear the memory

Edited 6 Years Ago by triumphost: n/a

Thank you so much for your explanation!!!!!!

i would change the "goto" structure into another format.....still trying

I have changed the structure by not using goto. but the problem still exists.

Attachments
#include <iostream>
#include <windows.h>
#include <string>
#include <cmath>
#include <limits>

using namespace std;

char locker_frame[9][77] = {"+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Locker   |  |  |  |  |  |  |  |  |  |  |  |",
		                    "+--+--+--+--+--+--+--+--+--+--+           +--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Control  |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+           +--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Panel    |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+"};

string locker_data[4][4][25];

static HANDLE hOut;
int clicked;

#define FW  FOREGROUND_RED |\
            FOREGROUND_GREEN |\
            FOREGROUND_BLUE

void gotoxy(unsigned short x, unsigned short y);
void rent_locker();
void cancel_locker();
void admin_mode();
void draw_locker(int location);
void initialize_locker_data();
void highlight(int x_coor1, int y_coor1,int x_coor2,int y_coor2, int color);
int check_available(int location,int row,int col);
int locker_remain(int location,int row,int col,int direction);

int main(){

    SetConsoleTitle("Locker Rental System");
    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
	initialize_locker_data();
main_menu:
    system("cls");
    char menu_option[3][30]={"1)Rent a locker\n",
		                     "2)Cancel a locker rental\n",
                             "3)Administrator mode\n"};

	cout << "Please Select an Option\n";
	cout << "     ==>" << menu_option[0];
	cout << "        " << menu_option[1];
	cout << "        " << menu_option[2];

	int key=1;
	do{
        if(GetAsyncKeyState(VK_UP) != 0){
            if(key>1){key-=1;}
        }else if(GetAsyncKeyState(VK_DOWN) != 0){
            if(key<3){key+=1;}
        }
		if(key!=1){
			gotoxy(0,key-1);
			cout << "        ";
                               SetConsoleTextAttribute(hOut,FW | 0);
			                   cout << menu_option[key-2];
		}
		if(key!=3){
			gotoxy(0,key+1);
			cout << "        ";
                               SetConsoleTextAttribute(hOut,FW | 0);
			                   cout << menu_option[key];
		}
		gotoxy(0,key);
		cout << "     ==>";
                           SetConsoleTextAttribute(hOut,BACKGROUND_GREEN |BACKGROUND_INTENSITY);
	                       cout << menu_option[key-1];
                           SetConsoleTextAttribute(hOut,FW | 0);
	
		Sleep(200);
	}while(!GetAsyncKeyState(13));

    switch(key){
	      case 1: rent_locker();
			      break;
		  case 2: cancel_locker();
			      break;
		  case 3: admin_mode();
	}

    goto main_menu;

	return 0;
}

void gotoxy(unsigned short x, unsigned short y)
{
    COORD WritePos;
    WritePos.X = x; 
    WritePos.Y = y;
    SetConsoleCursorPosition(hOut,WritePos);
}

void rent_locker(){
	char building[8][30]={"_____________________________",
		                  "|        Second Floor       |",
						  "_____________________________",
		                  "|        First Floor        |",
						  "_____________________________",
		                  "|     Ground Floor Shops    |",
						  "_____________________________",
						  "|     Basement Car Park     |"};
   int step=1;
   int stack_no=0;
   int i,j,k;
   string location_name;
   int x_position=0,y_position=0;

   
do{
   if(step==1){
      system("cls");

      cout << "Step 1: Please select a locker stack location:\n";

      for(i=0;i<8;i++){cout << "        " << building[i] << endl;}

      cout << "\nPress \"Back Space\" to return previous page";

      clicked=1;
      do{
          if(GetAsyncKeyState(VK_UP) != 0){
              if(stack_no>0){
			      stack_no-=1;
			      clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_DOWN) != 0){
              if(stack_no<3){
			      stack_no+=1;
  			      clicked=1;
			  }
		  }else if(GetAsyncKeyState(8) != 0){
              return;
		  }

	      if(clicked==1){
             if(stack_no!=0){
		        gotoxy(0,stack_no*2-1);
		        cout << "        ";
                                   SetConsoleTextAttribute(hOut,FW | 0);
			                       cout << building[stack_no*2-2] << endl;
                cout << "        "  << building[stack_no*2-1] << endl;
		                      
			 }
	         if(stack_no!=3){
		        gotoxy(0,stack_no*2+3);
		        cout << "        ";
                                   SetConsoleTextAttribute(hOut,FW | 0);
			                       cout << building[stack_no*2+2] << endl;
                cout << "        "  << building[stack_no*2+3] << endl;
			 }
	         gotoxy(0,stack_no*2+1);
	         cout << "        " << building[stack_no*2] << endl;
             cout << "     ==>" << building[stack_no*2+1] << endl;

             highlight(8,stack_no*2+1,36,stack_no*2+2,BACKGROUND_GREEN |BACKGROUND_INTENSITY);

		     clicked=0;
		  }

	      Sleep(200);
	      gotoxy(0,0);
	  }while(!GetAsyncKeyState(13));
      step=2;
   }else if(step==2){

      system("cls");

      switch(stack_no){
           case 3:location_name="Basement Car Park";
			      break;
		   case 2:location_name="Ground Floor Shops";
			      break;
		   case 1:location_name="First Floor";
			      break;
		   case 0:location_name="Second Floor";
	  }


      cout << "Locker Stack Location no. " << abs(stack_no-4) << " - " << location_name << endl;
      cout << "Daily charges: Top=$20, Bottom=$10, The Rest=$15\n\n";  
   
      draw_locker(stack_no);
   
      gotoxy(0,13);
      cout << "Press \"Back Space\" to return previous page";

      x_position=0;
      y_position=0;
   
      for(i=0;i<4;i++){
	      for(j=0;j<25;j++){
		      if(check_available(stack_no,i,j)==1){
			      x_position=j;
			      y_position=i;
			      break;
			  }
		  }
	      if(x_position!=0 || y_position !=0 || check_available(stack_no,0,0) == 1){break;}
          if(check_available(stack_no,0,0) == 0 && x_position == 0 && y_position == 0 ){
		      system("cls");
		      cout << "The Lockers in this location are full\n";
		      Sleep(3000);
		      return;
		  }
	  }

      clicked=1;
      do{
          if(GetAsyncKeyState(VK_UP) != 0){
              if(locker_remain(stack_no,y_position,x_position,0) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
					       FW | 0);
                 y_position=locker_remain(stack_no,y_position,x_position,0);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_DOWN) != 0){
              if(locker_remain(stack_no,y_position,x_position,1) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
					       FW | 0);
                 y_position=locker_remain(stack_no,y_position,x_position,1);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_LEFT) != 0){
              if(locker_remain(stack_no,y_position,x_position,2) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
					       FW | 0);
                 x_position=locker_remain(stack_no,y_position,x_position,2);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_RIGHT) != 0){
              if(locker_remain(stack_no,y_position,x_position,3) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
				   	       FW | 0);
                 x_position=locker_remain(stack_no,y_position,x_position,3);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(8) != 0){
              step=1;
		  }

	      if(clicked==1){
		      highlight(x_position*3,y_position*2+3,
			            x_position*3+3,y_position*2+5,
					    BACKGROUND_GREEN |BACKGROUND_INTENSITY);
		      clicked=0;
		  }

	      gotoxy(59,0);
	      string rental_price (locker_data[stack_no][y_position][x_position],2,2); 
          cout << "Rental Price: ";
          SetConsoleTextAttribute(hOut,FOREGROUND_RED | 
                                       FOREGROUND_GREEN |
									   FOREGROUND_INTENSITY);
	      cout << "$" << rental_price;
	      SetConsoleTextAttribute(hOut,FW |0);

          gotoxy(0,0);
	      Sleep(300);
	  }while(!(GetAsyncKeyState(13)));// & 0x8000;
      if(step!=1){step=3;}
   }else if(step==3){
      gotoxy(0,16);
      string rental_price (locker_data[stack_no][y_position][x_position],2,2); 
      cout << "The rental price is $" << rental_price << endl;
   
      fflush(stdin);
      char confirm[10];
      confirm[0]='u';
      do{
         cout << "Rent Paid(y/n): "<< flush;
	     fflush(stdin);
         cin.clear();
         cin >> confirm;
	  }while(strlen(confirm)>1 || !(confirm[0]=='y'||confirm[0]=='Y'||
	 		                        confirm[0]=='n'||confirm[0]=='N'));  

      fflush(stdin);
      if(confirm[0]=='y' || confirm[0]=='Y'){
	      confirm[0]='u';
	      cout << "*** PAID!!! ***";
	      cin.get();
		  step=4;
	  }else if(confirm[0]=='n' || confirm[0]=='N'){
	      confirm[0]='u';
	      step=2;
	  }

   }
 
}while(step!=4);

   return;
}

void cancel_locker(){
	system("cls");
    return;
}

void admin_mode(){
    system("cls");
	return;
}

void draw_locker(int location){
     int i,j,k;
     char temp_locker_frame[9][77];

     for(i=0;i<9;i++){
        for(j=0;j<77;j++){
		   temp_locker_frame[i][j]=locker_frame[i][j];
		}
	 }

	 for(j=0;j<4;j++){
		for(k=0;k<25;k++){
			string available (locker_data[location][j][k],0,1); 
            if(available=="n"){
			   	temp_locker_frame[j*2+1][k*3+1]='X';
				temp_locker_frame[j*2+1][k*3+

I hope so and I found bugs in your code aswell where if I type the confirm char before the price comes up, it skips confirming...

example:

if I press y = yes here... it skips asking
Do you want to pay 15$ for this locker?
cin>>x;
if (x == y)
{
  cout<<"paid";
}
else if(x == n)
{
  cout<<"choose a different locker";
}

it skips all of the code and goes back to the main menu...
another thing is lets say I choose a locker in the first *Column* and then press yes to confirm it, when I go to choose another locker aka the one right below it, it lets me choose whether or not to pay... while deciding if u want to pay, press the right arrow and u will see the previous choice from the first time...=> u will see the letter "y". now if I exit, restart, choose my first locker again(first COLUMN), paid.. and go to choose a second locker, *presses the right arrow*, *presses enter*, u will notice that the previous choice was already in memory and will be confirmed automatically when u press enter...

Fortunately for u... I just decided to spend 10 minutes and figure out how to fix this without doing all that clear memory bs... and the solution was:
when user presses right key during locker selection, automatically press backspace = erase last choice...
when user presses left key during locker selection, automatically press backspace = erase last choice.... and so on for every key pressed...

of course I had to change your other menu selection key that states... if user presses backspace, go back to previous menu... changed it to if user presses ESCAPE, automatically press enter and take them back to the previous menu...

this definitely solve your problem of clearing the stupid memory and u will find bugs that I have after testing your code for 10 minutes straight.. if u press n then select another locker and press y, u will see a bug that I have seen...

Here is the edited code...

if(GetAsyncKeyState(VK_LEFT) != 0){
       keybd_event(VK_BACK, 0, 0, 0); //that will fix memory issue. Allows new choice
       keybd_event(VK_BACK, 0, KEYEVENTF_KEYUP, 0);
              if(locker_remain(stack_no,y_position,x_position,2) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
					       FW | 0);
                 x_position=locker_remain(stack_no,y_position,x_position,2);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_RIGHT) != 0){
                keybd_event(VK_BACK, 0, 0, 0);
                keybd_event(VK_BACK, 0, KEYEVENTF_KEYUP, 0);
              if(locker_remain(stack_no,y_position,x_position,3) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
				   	       FW | 0);
                 x_position=locker_remain(stack_no,y_position,x_position,3);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_ESCAPE) != 0){
              step=1;
              keybd_event(VK_RETURN, 0, 0, 0);
              keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);

other minor fixes like void mainmenu(); added... U can obviously remove it and put it back how u want it... I was just testing it to see if it made a difference as I had that problem exactly two days ago on my own project (still incomplete due to school)... mainmenu(); does replace goto however.

Anyway the rest is really up to u.. your project.. I just liked it so continue what you were doing :).. dont forget that goto WILL NOT deconstruct stuff properly.. u can try this by compiling both of the codes below and see the difference.

For Your learning purposes: Notice the line #133 in questiontesting.cpp has rentlocker: and when your program reaches the part where u pay, press n and it will goto rentlocker and u will see that if u try to get a second locker, you will not be given a choice as the program has not decontructed.


Compare that to Untitled2.cpp where when u pay and press n, it calls the function rentlocker(); and since it decontructions perfectly, the user gets to choose a locker on the second choice...

GOOD LUCK! Great Project :)

Edited 6 Years Ago by triumphost: n/a

Attachments
#include <iostream>
#include <windows.h>
#include <string>
#include <cmath>
#include <limits>

using namespace std;

char locker_frame[9][77] = {"+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Locker   |  |  |  |  |  |  |  |  |  |  |  |",
		                    "+--+--+--+--+--+--+--+--+--+--+           +--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Control  |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+           +--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Panel    |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+"};

string locker_data[4][4][25];

static HANDLE hOut;
int clicked;

#define FW  FOREGROUND_RED |\
            FOREGROUND_GREEN |\
            FOREGROUND_BLUE

void gotoxy(unsigned short x, unsigned short y);
void rent_locker();
void cancel_locker();
void admin_mode();
void draw_locker(int location);
void initialize_locker_data();
void highlight(int x_coor1, int y_coor1,int x_coor2,int y_coor2, int color);
int check_available(int location,int row,int col);
int locker_remain(int location,int row,int col,int direction);
void mainmenu();

int main(){

    SetConsoleTitle("Locker Rental System");
    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
	initialize_locker_data();
    mainmenu();
}




void mainmenu()
{
     
    system("cls");
    char menu_option[3][30]={"1)Rent a locker\n",
		                     "2)Cancel a locker rental\n",
                             "3)Administrator mode\n"};

	cout << "Please Select an Option\n";
	cout << "     ==>" << menu_option[0];
	cout << "        " << menu_option[1];
	cout << "        " << menu_option[2];

	int key=1;
	do{
        if(GetAsyncKeyState(VK_UP) != 0){
            if(key>1){key-=1;}
        }else if(GetAsyncKeyState(VK_DOWN) != 0){
            if(key<3){key+=1;}
        }
		if(key!=1){
			gotoxy(0,key-1);
			cout << "        ";
                               SetConsoleTextAttribute(hOut,FW | 0);
			                   cout << menu_option[key-2];
		}
		if(key!=3){
			gotoxy(0,key+1);
			cout << "        ";
                               SetConsoleTextAttribute(hOut,FW | 0);
			                   cout << menu_option[key];
		}
		gotoxy(0,key);
		cout << "     ==>";
                           SetConsoleTextAttribute(hOut,BACKGROUND_GREEN |BACKGROUND_INTENSITY);
	                       cout << menu_option[key-1];
                           SetConsoleTextAttribute(hOut,FW | 0);
	
		Sleep(200);
	}while(!GetAsyncKeyState(13));

    switch(key){
	      case 1: rent_locker();
			      break;
		  case 2: cancel_locker();
			      break;
		  case 3: admin_mode();
		          break;
	}

    mainmenu();

	exit(0);
}



void gotoxy(unsigned short x, unsigned short y)
{
    COORD WritePos;
    WritePos.X = x; 
    WritePos.Y = y;
    SetConsoleCursorPosition(hOut,WritePos);
}


void rent_locker(){
	char building[8][30]={"_____________________________",
		                  "|        Second Floor       |",
						  "_____________________________",
		                  "|        First Floor        |",
						  "_____________________________",
		                  "|     Ground Floor Shops    |",
						  "_____________________________",
						  "|     Basement Car Park     |"};
   int step=1;
   int stack_no=0;
   int i,j,k;
   string location_name;
   int x_position=0,y_position=0;
do{
   if(step==1){
   rent_locker:
      system("cls");

      cout << "Step 1: Please select a locker stack location:\n";

      for(i=0;i<8;i++){cout << "        " << building[i] << endl;}

      cout << "\nPress \"Back Space\" to return previous page";

      clicked=1;
      do{
          if(GetAsyncKeyState(VK_UP) != 0){
              if(stack_no>0){
			      stack_no-=1;
			      clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_DOWN) != 0){
              if(stack_no<3){
			      stack_no+=1;
  			      clicked=1;
			  }
		  }else if(GetAsyncKeyState(8) != 0){
              return;
		  }

	      if(clicked==1){
             if(stack_no!=0){
		        gotoxy(0,stack_no*2-1);
		        cout << "        ";
                                   SetConsoleTextAttribute(hOut,FW | 0);
			                       cout << building[stack_no*2-2] << endl;
                cout << "        "  << building[stack_no*2-1] << endl;
		                      
			 }
	         if(stack_no!=3){
		        gotoxy(0,stack_no*2+3);
		        cout << "        ";
                                   SetConsoleTextAttribute(hOut,FW | 0);
			                       cout << building[stack_no*2+2] << endl;
                cout << "        "  << building[stack_no*2+3] << endl;
			 }
	         gotoxy(0,stack_no*2+1);
	         cout << "        " << building[stack_no*2] << endl;
             cout << "     ==>" << building[stack_no*2+1] << endl;

             highlight(8,stack_no*2+1,36,stack_no*2+2,BACKGROUND_GREEN |BACKGROUND_INTENSITY);

		     clicked=0;
		  }

	      Sleep(200);
	      gotoxy(0,0);
	  }while(!GetAsyncKeyState(13));
      step=2;
   }else if(step==2){
      system("cls");
      stack_no=0;
      switch(stack_no){ 
           case 3:location_name="Basement Car Park";
			      break;
		   case 2:location_name="Ground Floor Shops";
			      break;
		   case 1:location_name="First Floor";
			      break;
		   case 0:location_name="Second Floor";
		   break;
	  }


      cout << "Locker Stack Location no. " << abs(stack_no-4) << " - " << location_name << endl;
      cout << "Daily charges: Top=$20, Bottom=$10, The Rest=$15\n\n";  
   
      draw_locker(stack_no);
   
      gotoxy(0,13);
      cout << "Press \"The Escape Button\" to return previous page";

      x_position=0;
      y_position=0;
   
      for(i=0;i<4;i++){
	      for(j=0;j<25;j++){
		      if(check_available(stack_no,i,j)==1){
			      x_position=j;
			      y_position=i;
			      break;
			  }
		  }
	      if(x_position!=0 || y_position !=0 || check_available(stack_no,0,0) == 1){break;}
          if(check_available(stack_no,0,0) == 0 && x_position == 0 && y_position == 0 ){
		      system("cls");
		      cout << "The Lockers in this location are full\n";
		      Sleep(3000);
		      return;
		  }
	  }

      clicked=1;
      do{
          if(GetAsyncKeyState(VK_UP) != 0){
                keybd_event(VK_BACK, 0, 0, 0);
                keybd_event(VK_BACK, 0, KEYEVENTF_KEYUP, 0);
              if(locker_remain(stack_no,y_position,x_position,0) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
					       FW | 0);
                 y_position=locker_remain(stack_no,y_position,x_position,0);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_DOWN) != 0){
                keybd_event(VK_BACK, 0, 0, 0);
                keybd_event(VK_BACK, 0, KEYEVENTF_KEYUP, 0);
              if(locker_remain(stack_no,y_position,x_position,1) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
					       FW | 0);
                 y_position=locker_remain(stack_no,y_position,x_position,1);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_LEFT) != 0){
                keybd_event(VK_BACK, 0, 0, 0);
                keybd_event(VK_BACK, 0, KEYEVENTF_KEYUP, 0);
              if(locker_remain(stack_no,y_position,x_position,2) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
					       FW | 0);
                 x_position=locker_remain(stack_no,y_position,x_position,2);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_RIGHT) != 0){
                keybd_event(VK_BACK, 0, 0, 0);
                keybd_event(VK_BACK, 0, KEYEVENTF_KEYUP, 0);
              if(locker_remain(stack_no,y_position,x_position,3) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
				   	       FW | 0);
                 x_position=locker_remain(stack_no,y_position,x_position,3);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_ESCAPE) != 0){
              step=1;
              keybd_event(VK_RETURN, 0, 0, 0);
              keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
		  }

	      if(clicked==1){
		      highlight(x_position*3,y_position*2+3,
			            x_position*3+3,y_position*2+5,
					    BACKGROUND_GREEN |BACKGROUND_INTENSITY);
		      clicked=0;
		  }

	      gotoxy(59,0);
	      string rental_price (locker_data[stack_no][y_position][x_position],2,2); 
          cout << "Rental Price: ";
          SetConsoleTextAttribute(hOut,FOREGROUND_RED | 
                                       FOREGROUND_GREEN |
									   FOREGROUND_INTENSITY);
	      cout << "$" << rental_price;
	      SetConsoleTextAttribute(hOut,FW |0);

          gotoxy(0,0);
	      Sleep(300);
	  }while(!(GetAsyncKeyState(13)));// & 0x8000;
      if(step!=1){step=3;}
   }else if(step==3){
      gotoxy(0,16);
      string rental_price (locker_data[stack_no][y_position][x_position],2,2); 
      cout << "The rental price is $" << rental_price << endl;
   
      fflush(stdin);
      char confirm[10];
      confirm[0]='u';
      do{
         cout << "Rent Paid(y/n): "<< flush;
	     fflush(stdin);
         cin >> confirm;
	  }while(strlen(confirm)>1 || !(confirm[0]=='y'||confirm[0]=='Y'||
	 		                        confirm[0]=='n'||confirm[0]=='N'));  

      fflush(stdin);
      if(confirm[0]=='y' || confirm[0]=='Y'){
	      confirm[0]='u';
	      cout << "*** PAID!!! ***\n\n";
	      cin.get();
		  step=4;
	  }
#include <iostream>
#include <windows.h>
#include <string>
#include <cmath>
#include <limits>

using namespace std;

char locker_frame[9][77] = {"+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Locker   |  |  |  |  |  |  |  |  |  |  |  |",
		                    "+--+--+--+--+--+--+--+--+--+--+           +--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Control  |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+           +--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  Panel    |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+",
                            "|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |",
					        "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+"};

string locker_data[4][4][25];

static HANDLE hOut;
int clicked;

#define FW  FOREGROUND_RED |\
            FOREGROUND_GREEN |\
            FOREGROUND_BLUE

void gotoxy(unsigned short x, unsigned short y);
void rent_locker();
void cancel_locker();
void admin_mode();
void draw_locker(int location);
void initialize_locker_data();
void highlight(int x_coor1, int y_coor1,int x_coor2,int y_coor2, int color);
int check_available(int location,int row,int col);
int locker_remain(int location,int row,int col,int direction);
void mainmenu();

int main(){

    SetConsoleTitle("Locker Rental System");
    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
	initialize_locker_data();
    mainmenu();
}




void mainmenu()
{
     
    system("cls");
    char menu_option[3][30]={"1)Rent a locker\n",
		                     "2)Cancel a locker rental\n",
                             "3)Administrator mode\n"};

	cout << "Please Select an Option\n";
	cout << "     ==>" << menu_option[0];
	cout << "        " << menu_option[1];
	cout << "        " << menu_option[2];

	int key=1;
	do{
        if(GetAsyncKeyState(VK_UP) != 0){
            if(key>1){key-=1;}
        }else if(GetAsyncKeyState(VK_DOWN) != 0){
            if(key<3){key+=1;}
        }
		if(key!=1){
			gotoxy(0,key-1);
			cout << "        ";
                               SetConsoleTextAttribute(hOut,FW | 0);
			                   cout << menu_option[key-2];
		}
		if(key!=3){
			gotoxy(0,key+1);
			cout << "        ";
                               SetConsoleTextAttribute(hOut,FW | 0);
			                   cout << menu_option[key];
		}
		gotoxy(0,key);
		cout << "     ==>";
                           SetConsoleTextAttribute(hOut,BACKGROUND_GREEN |BACKGROUND_INTENSITY);
	                       cout << menu_option[key-1];
                           SetConsoleTextAttribute(hOut,FW | 0);
	
		Sleep(200);
	}while(!GetAsyncKeyState(13));

    switch(key){
	      case 1: rent_locker();
			      break;
		  case 2: cancel_locker();
			      break;
		  case 3: admin_mode();
		          break;
	}

    mainmenu();

	exit(0);
}



void gotoxy(unsigned short x, unsigned short y)
{
    COORD WritePos;
    WritePos.X = x; 
    WritePos.Y = y;
    SetConsoleCursorPosition(hOut,WritePos);
}


void rent_locker(){
	char building[8][30]={"_____________________________",
		                  "|        Second Floor       |",
						  "_____________________________",
		                  "|        First Floor        |",
						  "_____________________________",
		                  "|     Ground Floor Shops    |",
						  "_____________________________",
						  "|     Basement Car Park     |"};
   int step=1;
   int stack_no=0;
   int i,j,k;
   string location_name;
   int x_position=0,y_position=0;
do{
   if(step==1){
      system("cls");

      cout << "Step 1: Please select a locker stack location:\n";

      for(i=0;i<8;i++){cout << "        " << building[i] << endl;}

      cout << "\nPress \"Back Space\" to return previous page";

      clicked=1;
      do{
          if(GetAsyncKeyState(VK_UP) != 0){
              if(stack_no>0){
			      stack_no-=1;
			      clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_DOWN) != 0){
              if(stack_no<3){
			      stack_no+=1;
  			      clicked=1;
			  }
		  }else if(GetAsyncKeyState(8) != 0){
              return;
		  }

	      if(clicked==1){
             if(stack_no!=0){
		        gotoxy(0,stack_no*2-1);
		        cout << "        ";
                                   SetConsoleTextAttribute(hOut,FW | 0);
			                       cout << building[stack_no*2-2] << endl;
                cout << "        "  << building[stack_no*2-1] << endl;
		                      
			 }
	         if(stack_no!=3){
		        gotoxy(0,stack_no*2+3);
		        cout << "        ";
                                   SetConsoleTextAttribute(hOut,FW | 0);
			                       cout << building[stack_no*2+2] << endl;
                cout << "        "  << building[stack_no*2+3] << endl;
			 }
	         gotoxy(0,stack_no*2+1);
	         cout << "        " << building[stack_no*2] << endl;
             cout << "     ==>" << building[stack_no*2+1] << endl;

             highlight(8,stack_no*2+1,36,stack_no*2+2,BACKGROUND_GREEN |BACKGROUND_INTENSITY);

		     clicked=0;
		  }

	      Sleep(200);
	      gotoxy(0,0);
	  }while(!GetAsyncKeyState(13));
      step=2;
   }else if(step==2){
      system("cls");
      stack_no=0;
      switch(stack_no){ 
           case 3:location_name="Basement Car Park";
			      break;
		   case 2:location_name="Ground Floor Shops";
			      break;
		   case 1:location_name="First Floor";
			      break;
		   case 0:location_name="Second Floor";
		   break;
	  }


      cout << "Locker Stack Location no. " << abs(stack_no-4) << " - " << location_name << endl;
      cout << "Daily charges: Top=$20, Bottom=$10, The Rest=$15\n\n";  
   
      draw_locker(stack_no);
   
      gotoxy(0,13);
      cout << "Press \"The Escape Button\" to return previous page";

      x_position=0;
      y_position=0;
   
      for(i=0;i<4;i++){
	      for(j=0;j<25;j++){
		      if(check_available(stack_no,i,j)==1){
			      x_position=j;
			      y_position=i;
			      break;
			  }
		  }
	      if(x_position!=0 || y_position !=0 || check_available(stack_no,0,0) == 1){break;}
          if(check_available(stack_no,0,0) == 0 && x_position == 0 && y_position == 0 ){
		      system("cls");
		      cout << "The Lockers in this location are full\n";
		      Sleep(3000);
		      return;
		  }
	  }

      clicked=1;
      do{
          if(GetAsyncKeyState(VK_UP) != 0){
                keybd_event(VK_BACK, 0, 0, 0);
                keybd_event(VK_BACK, 0, KEYEVENTF_KEYUP, 0);
              if(locker_remain(stack_no,y_position,x_position,0) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
					       FW | 0);
                 y_position=locker_remain(stack_no,y_position,x_position,0);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_DOWN) != 0){
                keybd_event(VK_BACK, 0, 0, 0);
                keybd_event(VK_BACK, 0, KEYEVENTF_KEYUP, 0);
              if(locker_remain(stack_no,y_position,x_position,1) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
					       FW | 0);
                 y_position=locker_remain(stack_no,y_position,x_position,1);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_LEFT) != 0){
                keybd_event(VK_BACK, 0, 0, 0);
                keybd_event(VK_BACK, 0, KEYEVENTF_KEYUP, 0);
              if(locker_remain(stack_no,y_position,x_position,2) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
					       FW | 0);
                 x_position=locker_remain(stack_no,y_position,x_position,2);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_RIGHT) != 0){
                keybd_event(VK_BACK, 0, 0, 0);
                keybd_event(VK_BACK, 0, KEYEVENTF_KEYUP, 0);
              if(locker_remain(stack_no,y_position,x_position,3) != -1){
			     highlight(x_position*3,y_position*2+3,
			               x_position*3+3,y_position*2+5,
				   	       FW | 0);
                 x_position=locker_remain(stack_no,y_position,x_position,3);
			     clicked=1;
			  }
		  }else if(GetAsyncKeyState(VK_ESCAPE) != 0){
              step=1;
              keybd_event(VK_RETURN, 0, 0, 0);
              keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
		  }

	      if(clicked==1){
		      highlight(x_position*3,y_position*2+3,
			            x_position*3+3,y_position*2+5,
					    BACKGROUND_GREEN |BACKGROUND_INTENSITY);
		      clicked=0;
		  }

	      gotoxy(59,0);
	      string rental_price (locker_data[stack_no][y_position][x_position],2,2); 
          cout << "Rental Price: ";
          SetConsoleTextAttribute(hOut,FOREGROUND_RED | 
                                       FOREGROUND_GREEN |
									   FOREGROUND_INTENSITY);
	      cout << "$" << rental_price;
	      SetConsoleTextAttribute(hOut,FW |0);

          gotoxy(0,0);
	      Sleep(300);
	  }while(!(GetAsyncKeyState(13)));// & 0x8000;
      if(step!=1){step=3;}
   }else if(step==3){
      gotoxy(0,16);
      string rental_price (locker_data[stack_no][y_position][x_position],2,2); 
      cout << "The rental price is $" << rental_price << endl;
   
      fflush(stdin);
      char confirm[10];
      confirm[0]='u';
      do{
         cout << "Rent Paid(y/n): "<< flush;
	     fflush(stdin);
         cin >> confirm;
	  }while(strlen(confirm)>1 || !(confirm[0]=='y'||confirm[0]=='Y'||
	 		                        confirm[0]=='n'||confirm[0]=='N'));  

      fflush(stdin);
      if(confirm[0]=='y' || confirm[0]=='Y'){
	      confirm[0]='u';
	      cout << "*** PAID!!! ***\n\n";
	      cin.get();
		  step=4;
	  }else if(confirm[0

Thank you so much. I finally solve this problem with ur solution.
hope you can also get a good academic result in ur school.

This article has been dead for over six months. Start a new discussion instead.