Thread: declare function to allow user have second chance enter choice

  1. #1
    Registered User
    Join Date
    Jul 2017
    Posts
    48

    declare function to allow user have second chance enter choice

    i', develop a math program now , how can i allow my user to have second chance when they enter wrongly?


    Code:
    void additionmenu()
    {
        char choice;
        printf("Please select the level\n");
        printf("A level 1\n");
        printf("B level 2\n");
        printf("C level 3\n");
        scanf("%c", &choice);
        if (choice == 'A' || choice == 'a')
        {
            printf("You have selected level 1\n");
            addEasy();
        }
        else if (choice == 'B' || choice == 'b')
        {
            printf("You have selected level 2\n");
            addMedium();
        }
        else if (choice == 'C' || choice == 'c')
        {
            printf("You have selected level 3\n");
            addDifficult();
        }
        else
        {
            printf("Invalid choice\n");
            menu();
        }
        rewind(stdin);
        return choice;
    }

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Adding all this inside a loop would be a good solution, maybe with a counter to count how many times the user tried to input something, and maybe aborting after N tries.
    Devoted my life to programming...

  3. #3
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    You are using rewind() on stdin? Is that sensible?

  4. #4
    Registered User
    Join Date
    Jul 2017
    Posts
    48
    can u show me a example?

  5. #5
    Registered User
    Join Date
    Jul 2017
    Posts
    48
    can u help me look at my another code?

  6. #6
    Registered User
    Join Date
    Nov 2015
    Posts
    119
    Code:
    #include <iostream>
    
    
    
    int main()
    {
        bool b=1;
        while(b)
            {
                std::cout<< "Введіть 1 для продовження або 0 для виходу"<< std::endl;
                std::cin>> b;
    
            }
       return 0;
    }
    I may have not understood what you wanted?
    Last edited by Dmy; 08-03-2017 at 04:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. user input pre-enter string?
    By mikeyp in forum C++ Programming
    Replies: 4
    Last Post: 11-25-2009, 02:59 PM
  2. Replies: 4
    Last Post: 08-31-2009, 11:04 AM
  3. user can hit enter all day long
    By Ash1981 in forum C Programming
    Replies: 7
    Last Post: 01-01-2006, 05:33 AM
  4. Replies: 8
    Last Post: 04-07-2004, 01:29 PM
  5. Getting input without the user having to press Enter...
    By Ranedhel in forum C++ Programming
    Replies: 18
    Last Post: 07-16-2003, 05:36 PM

Tags for this Thread