delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/09/18/10:47:59

From: "Jenny Reeves" <jenny DOT reeves AT s-4-b DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Getche doesnt work!
Date: Tue, 17 Sep 2002 17:00:27 +0100
Lines: 167
Message-ID: <am7jh7$ru1$1$8300dec7@news.demon.co.uk>
NNTP-Posting-Host: demon-gw.unidirect.co.uk
X-Trace: news.demon.co.uk 1032278376 28609 193.195.114.41 (17 Sep 2002 15:59:36 GMT)
X-Complaints-To: abuse AT demon DOT net
NNTP-Posting-Date: Tue, 17 Sep 2002 15:59:36 +0000 (UTC)
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
X-Priority: 3
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MSMail-Priority: Normal
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Getche doesnt work!

Hello,

I was hoping someone could help me with my program, everything is working
fine apart from getche function in one of my functions (apologies if my
terminology is wrong).  Its a basic cash machine program that goes to a
welcome screen then takes and verifies the users account and PIN number
before taking them to the main menu: the user can then select between 1-5 (5
being quit whole program). The problem is the user has to press any key
twice when entering their choice, if they press enter once it just goes to
the next line, and doesn't accept the choice until you've pressed it twice?
main code for the program is -
void main() /*Main program will define the order in which the the functions
run*/
{



      AccFile = fopen(FileName      ,"r+");/*Opens the Accounts.dat file to
AccFile (temporary space in RAM)*/

      fill_array();  /*reads account.dat file into struct accounts*/



      do/*This is a Do While Loop, it will run this part of the program
until the variable Choice is equal to 5 which in the main menu is "Quit"*/

      {

            welcome();

            get_acc_no();

            get_pin();



            if (match == 'Y') /*This is an IF statement if the variable
"match" = Y   then do this*/

                           /*If not start again with welcome screen the
match variable appears in the get_pin function*/

                  {

                  menu();

                  get_choice();

                  do_choice();

                  }

      }while (choice !=5);



      rewind(AccFile);/*Rewinds file from las time it was Written*/



      for (i=0;i<=9;i++)/*Do the Write File function 10 times, this enables
all ten accounts and any new info entered by the user in RAM to be written
to permanent memory*/

      write_file(AccFile,accounts[i]);



      fclose(AccFile);/*Close the AccFile*/

}

The get choice fuction is -





void get_choice()

{

 gotoxy(21,22);

 printf("Please enter your choice: ");

 scanf("%d",&choice);

 getche();

 }

The function that follows is do choice -



void do_choice()

{

  switch (choice) {



  case 1:

      balance();

      break;

  case 2:

      withdraw();

      break;

  case 3:

      deposit();

      break;

  case 4:

      help();

      break;

  case 5:

       clrscr();

       gotoxy(21,11);

       printf("EXITING CASHPOINT PROGRAM!......... ");

       break;

  case 6:

      printf("\n ERROR you have selected an invalid option");

       getche();

       break;

      }



}


Any help, greatly appreciated


Chrs,

Jenny





- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019