Thread: Assigning exit key

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    4

    Assigning exit key

    hello sorry if i had posted something that is already available coz i've search this but to no avail.what i want to do is assign the q key to quit the program what is the command line?

  2. #2
    ! |-| /-\ +3 1337 Yawgmoth's Avatar
    Join Date
    Dec 2002
    Posts
    187
    http://cboard.cprogramming.com/showt...threadid=31169
    Tells you how to do this and similar things.
    L33t sp3@k sux0rz (uZ it t@k3s 10 m1|\|ut3s 2 tr@nzl@te 1 \/\/0rd & th3n j00 h@\/3 2 g3t p@$t d@ m1zpelli|\|gz, @tr0(i0u$ gr@mm@r @|\|d 1n(0/\/\pr3#3|\|$1bl3 $l@|\|g. 1t p\/\/33nz j00!!

    Speling is my faverit sujekt

    I am a signature virus. Add me to your signature so that I may multiply.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    4
    Code:
     #include <stdio.h>
    #include <iostream.h>
    #include <conio.h>
    using namespace std;
    
    int main()
    {
       char q,x;
       int choice = 0;
       int nilai;
       int jumlah;
       char b;
            a: cout    << endl
            << "***********************************************************" << endl
            << "*Masukkan Jumlah Jualan Anda                              *" << endl
            << "*Anda Boleh Memilih Dari Salah Satu Pilihan Di Bawah:     *" << endl     //welcome msg i written it in my language
            << endl << "*1 Jika Jumlah Anda 5000 Pilih Opsyen Ini                 *"   //1st option for the user
            << endl << "*2 Jika Jumlah Anda 6000 Pilih Opsyen Ini                 *"   //2nd option
            << endl << "*3 Jika Jumlah Anda 7000 Pilih Opsyen Ini                 *"    //3rd option
            << endl << "*4 Jika Jumlah Anda Lebih Dari 7000 Pilih Opsyen Ini      *" << endl //4th option
            << endl << "*Masukkan Pilihan Anda:                                   *" << endl;
    
        cin >> choice; //where user key in the input
    
    
    
       switch(choice)
       {
          case 1: cout << endl << "Gaji Anda Ialah RM 650"
                       << endl;
                  break;
          case 2: cout << endl << "Gaji Anda Ialah RM 740"
                       << endl;
                  break;
          case 3: cout << endl << "Gaji Anda Ialah RM 830"
                       << endl;
                  break;
          case 4: cout << endl << "Masukkan Jumlah Jualan Anda \n ";
                  cin  >> nilai;
    
                  if (nilai > 0)
                  jumlah=nilai/100*9+200;
                  cout << "Gaji Anda Ialah: \n RM";
                  cout << jumlah;
    
                  break;
          default: cout << endl <<"Anda Telah Memasukkan Pilihan Yang Salah."
                        << endl;
       }
                  cout<<"\n****************************************************\n";
                  cout<<"\nAdakah Anda Ingin Teruskan Aplikasi?[y/n]:"; //asking whether user wants to quit or not
                  cin>>b;
                  if(b=='y'||b== 'Y')
                  goto a;
                  else
                  return 0;
    
    
    }
    what i want to do is that assigning a quit key before the user key in any optionthat had been given.if can where should i put it?tried the swith but both default interfered with one another.

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    4
    Originally posted by vVv
    I don't understand your problem. Maybe make choice a ``char''

    Code:
    cin >> choice; //where user key in the input
    if( choice == 'q' )
      return 0;
    And then replace the switch cases through ascii digits (case '1', case '2', etc).

    how do i set through ascii?


    whenevr i set q as my quit button
    the program suddenly loop continously until i click the x button

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    4
    waht if i want to print out the output?what is the code?and i heard about "black window" what is that?from what i've heard it got something to do with printing and a code,if theres such a thing what is it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM