Thread: Please any key to continue...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    6

    Please any key to continue...

    Hi All~ I'm New from here and new user for C++.

    My program will display a menu. And push 'Q' or 'q' to exit the program.
    I would like to display a message after this. Then click 'any key' to exit the program.
    But it will auto quit after i click 'Q' or 'q'.

    Any suggestion? What should i do? Thanks.


    #include <iostream.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>


    //# include <iostream>
    using namespace std;

    class Menu
    {
    char option;
    public:
    void display(void);
    void process(void);
    char getOption()
    { return option; }
    };

    void Menu::display()
    {
    cout << "\n\nSuper Cheap Super Drinks \n\n";
    cout << "Brands available: \n\n";
    cout << "1. <C>oke $1.30 \n";
    cout << "2. <S>prite $1.20 \n";
    cout << "3. <F>anta $1.10 \n";
    cout << "4. <R>otTooth $0.90 \n";
    cout << "5. SuperFi<Z> $1.00 \n\n";
    cout << "Please select a brand: ";
    cin >> option;
    }

    void Menu:rocess()
    {
    switch(option)
    {
    case '1': cout << "\nCOKE DISPENSED. HAVE A NICE DAY!";
    break;
    case 'C': cout << "\nCOKE DISPENSED. HAVE A NICE DAY!";
    break;
    case 'c': cout << "\nCOKE DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case '2': cout << "\nSPRITE DISPENSED. HAVE A NICE DAY!";
    break;
    case 'S': cout << "\nSPRITE DISPENSED. HAVE A NICE DAY!";
    break;
    case 's': cout << "\nSPRITE DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case '3': cout << "\nFANTA DISPENSED. HAVE A NICE DAY!";
    break;
    case 'F': cout << "\nFANTA DISPENSED. HAVE A NICE DAY!";
    break;
    case 'f': cout << "\nFANTA DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case '4': cout << "\nROTTOOTH DISPENSED. HAVE A NICE DAY!";
    break;
    case 'R': cout << "\nROTTOOTH DISPENSED. HAVE A NICE DAY!";
    break;
    case 'r': cout << "\nROTTOOTH DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case '5': cout << "\nSUPERFIZ DISPENSED. HAVE A NICE DAY!";
    break;
    case 'Z': cout << "\nSUPERFIZ DISPENSED. HAVE A NICE DAY!";
    break;
    case 'z': cout << "\nSUPERFIZ DISPENSED. HAVE A NICE DAY!";
    break;
    //
    case 'Q': cout << "\nPlease any key to continue......\n";
    cin.get();
    break;
    case 'q': cout << "\nPlease any key to continue......\n";
    cin.get();
    break;
    //
    default : cout << "\nNOT A VALID SELECTION. PLEASE SELECT AGAIN ";
    }
    }



    class Manager
    {
    Menu menu;
    public:
    void iterateMenu();
    };

    void Manager::iterateMenu()
    {
    do
    {
    menu.display();
    menu.process();
    } while((menu.getOption()!='Q')&&(menu.getOption()!= 'q'));



    };


    void main()
    {
    Manager start;
    start.iterateMenu();
    };

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    just do a

    Code:
    cout << "Press any key to continue..." << endl;
    getch();

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    6
    O.YES~ THANKS~~

  4. #4
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Also, to save yourself all that typing, instead of this:
    Code:
    case '5': cout << "\nSUPERFIZ DISPENSED. HAVE A NICE DAY!";
    break;
    case 'Z': cout << "\nSUPERFIZ DISPENSED. HAVE A NICE DAY!";
    break;
    case 'z': cout << "\nSUPERFIZ DISPENSED. HAVE A NICE DAY!";
    break;
    do this:
    Code:
    case '5': case 'Z': case 'z': 
    cout << "\nSUPERFIZ DISPENSED. HAVE A NICE DAY!";
    break;

  5. #5
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    for the "press any key..." you can do this too:
    Code:
    system("pause");

  6. #6
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Originally posted by Vber
    for the "press any key..." you can do this too:
    Code:
    system("pause");
    Wouldn't that be limiting system-wise? As in not work on other OSes?

  7. #7
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    so would getch() but that's life
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    6
    thanks all.

    And if i tried to add a class for store the information of "Coins, Cans number & Brand" to make it works as a vending machine. I should add a New class of "Container" to store of this information?

    Another question is about constructor & destructor.
    I'm still not very understand how to use it. So i would like to see some example of how to use this. Have any example can show me? Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. need help program crashing
    By tunerfreak in forum C++ Programming
    Replies: 14
    Last Post: 05-22-2006, 11:29 AM
  3. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  4. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM