CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2016
    Posts
    1

    Unhappy Assignment due in 1 day (Not showing valid) ISBN errors also.

    Hey guys i really need help ASAP..

    Code:
    #include <iostream>
    #include <limits>
    
    void draw_menu()
    {
        std::cout << "******************************************************************\n"
                  << "* choose an entry from 1 to 3.  *\n"
                  << "* [1] validate modulus 11 number  *\n"
                  << "* [2] validate data  *\n"
                  << "* [3] quit  *\n"
                  << "******************************************************************\n";
    }
    
    int get_number() // read a valid number from stdin
    {
        int number ;
        if( std::cin >> number ) return number ;
    
        // invalid input, inform the user, clear the input buffer and try again
        std::cout << "invalid number. please re-enter\n" ;
        std::cin.clear() ;
        std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
        return get_number() ;
    }
    
    int get_choice() // display the menu, return valid choice entered by the user
    {
        draw_menu() ;
    
        const int choice = get_number() ;
        if( choice >= 1 && choice <= 3 ) return choice ; // valid choice
    
        return get_choice() ; // invalid choice, try again
    }
    
    bool valid_date( int dd, int mm, int yy )
    {
        // *** TO DO: validate that dd/mm/yy forms a valid date
        //            if valid, return true
    
        return false ;
    }
    
    bool valid_modulo_11( int number )
    {
        // *** TO DO: validate that number is a valid modulo 11 number
        //            if valid, return true
    
        return false ;
    }
    
    int main()
    {
        bool quit = false ;
    
        do
        {
            const int choice = get_choice() ;
    
            switch(choice)
            {
                case 1:
                {
                    std::cout << "enter modulo 11 number: " ;
                    const int number = get_number() ;
    
                    if( valid_modulo_11(number) ) std::cout << "yes, valid modulo 11 number\n" ;
                    else std::cout << "that is not a valid modulo 11 number\n" ;
    
                    break ;
                }
    
                case 2:
                {
                    std::cout << "enter day: " ;
                    const int dd = get_number() ;
                    std::cout << "enter month: " ;
                    const int mm = get_number() ;
                    std::cout << "enter year: " ;
                    const int yy = get_number() ;
    
                    if( valid_date( dd, mm, yy ) ) std::cout << "valid date\n" ;
                    else std::cout << "invalid date\n" ;
    
                    break ;
                }
    
                case 3: quit = true ;
            }
    
        } while( !quit ) ;
    }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Assignment due in 1 day (Not showing valid) ISBN errors also.

    You don't have any code that would validate the number. Have you been given an algorithm do to it?

    Please be a bit more specific about what's wrong.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,923

    Re: Assignment due in 1 day (Not showing valid) ISBN errors also.

    Your code at present will always say that any number is not a valid modulo 11 number as the function always returns false! You need to provide the code for valid_modulo_11().
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured