Menu

This is a discussion on Menu within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by paulogrady you should be able to write code. She seems to write code just fine. You are ...

  1. #16
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by paulogrady View Post
    you should be able to write code.
    She seems to write code just fine. You are the one who had a basic principle being taught to them and instead of doing some critical thinking you opted to just re-ask the question and avoid the person answering your question with both an answer and a methodology.

    tolower(x) will return a lower case version of x.

    Thus:

    switch(x) is still going to check x.

    In other words, x is not lowercase-ified...unless it was lowercase to begin with

    switch(tolower(x)) will check a lowercase version of x.

    You should be able to comprehend now.

  2. #17
    Registered User
    Join Date
    May 2008
    Posts
    28

    Lightbulb

    Quote Originally Posted by paulogrady View Post
    Hi

    I want to create a menu but only with 2 choices: a, b.
    Use tolower function on the input and use it for making an assignment statement.
    If the user enters an incorrect character then the screen will clear and they will be prompted with the same question again.

    How do I do this?
    Point taken with the tolower function.

    But I really want the best method for catching a user input error. Can you offer some advice or an example piece of code?

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    This may probably be somewhat overcourse, but how I'd generally like to do it is:
    Code:
    std::string input;
    std::getline(input, cin);
    int x;
    try
    {
        x = boost::lexical_cast<int>(input);
    }
    catch(boost::bad_lexical_cast&)
    {
        // Invalid input code here
    }
    // Input OK
    Of course, it requires boost.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User
    Join Date
    May 2008
    Posts
    28

    Question

    ne 1 else?

  5. #20
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    Do something similar to what Elysia said but using the standard C++ libs

    Using std::string and std::getline
    http://www.cplusplus.com/reference/string/string/
    http://www.cplusplus.com/reference/string/getline.html

    Using isdigit
    http://www.cplusplus.com/reference/c...e/isdigit.html
    Woop?

  6. #21
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,622
    Boost is generally portable, however, so it's not that much of a bad deal.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Replies: 2
    Last Post: 03-05-2009, 09:25 AM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21