Menu

This is a discussion on Menu within the C++ Programming forums, part of the General Programming Boards category; Hi I want to create a menu but only with 2 choices: a, b. Use tolower function on the input ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    28

    Menu

    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?

    Thanks

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    28
    thanks for reply.

    i can do clear screen ... system("cls");


    Ive had a go this is what I get:

    Code:
    for (;;)
    {
    	cout << "\nPlease choose a value for e/KT ratio:\n\n(a) e/KT = 20\n\n(b) e/KT = 40\n\nPlease enter a or b:";
    	cin >> choose;
    	tolower(choose);
    
    	switch (choose)
    	{
    	case 'a':
    		cout << "bye";
    		break;
    	case 'b':
    		cout << "hi";
    		break;
    	default:
    		cout << "Invalid option. Please choose again: ";
    	}
    	break;
    }
    Obviously, this is wrong i can understand why.

    I would just like a technique of keeping the initial question in the loop to be kept being answered as long as an invalid option is inputted.

    thanks

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    28
    What would be the best, most efficient way to do this.

    With for, while or switch

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    A switch is fine.
    The problem is, that if you would read the documentation, you would understand that tolower does not change the original value you input, but actually returns the lower case input, so you need to reassign it somewhere. Otherwise it's pretty pointless to call the function in the first place.
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    28

    Question

    Quote Originally Posted by Elysia View Post
    A switch is fine.
    The problem is, that if you would read the documentation, you would understand that tolower does not change the original value you input, but actually returns the lower case input, so you need to reassign it somewhere. Otherwise it's pretty pointless to call the function in the first place.
    Isnt that what I did above?

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    Nope.
    Code:
    tolower(choose);
    I see no assignment, do you?
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  8. #8
    Registered User
    Join Date
    May 2008
    Posts
    28
    so tell me what to do then

    the link you gave dont mention this

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    No, it didn't, but you should understand.
    Code:
    int foo(int x) { return x + 10; }
    int main()
    {
        int x = 10;
        foo(x);
        cout << x;
    }
    What will this print?
    Last edited by Elysia; 10-02-2008 at 09:10 AM.
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  10. #10
    Registered User
    Join Date
    May 2008
    Posts
    28

    Smile

    I dont know.

    Can someone just answer my original question pls?

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    The point is that I'm trying to teach why it doesn't work and what you must do to solve it.
    Handing out the answer just won't have the same effect.
    You should be able to read code.
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  12. #12
    Registered User
    Join Date
    May 2008
    Posts
    28
    p.s. you cant return an int to void... can you?

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    You're right... it should be int, hehe. Oops :P
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  14. #14
    Registered User
    Join Date
    May 2008
    Posts
    28
    you should be able to write code.

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    Everyone makes mistakes. Compilers catch mistakes!
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Page 1 of 2 12 LastLast
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