Thread: Menu

  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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

  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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

  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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

  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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

  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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

  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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

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

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

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, 10: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