CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2017
    Posts
    2

    input to determine even and odd numbers

    Hello all, I am new to c++ and I am currently taking a class, but my teacher doesn't really teach anything which is why I am soliciting help. My current problem is that I'm not sure sure how to go about to solve my problem.



    The problem: Ask user to input a positive integer then the output should show the odds and even numbers from the number entered

    Example, if the user inputs the number '1426' then my codes output should show the even numbers from the number entered.
    Even numbers entered: 2,4,6

    It should also show the odd numbers as well. Example, if user inputs '134' then it should show....
    Odd numbers entered: 1,3



    Any help or tips would be very appreciative. Like i said, I'm only a month into my c++ class, so any help would be great.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: input to determine even and odd numbers

    Well, let's start from the very begin: do you know how to test a number being even or odd?
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2017
    Posts
    2

    Re: input to determine even and odd numbers

    No i don't. We haven't covered that or arrays. We have just started on some basic loops.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: input to determine even and odd numbers

    Quote Originally Posted by carcrashradio View Post
    No i don't. We haven't covered that or arrays. We have just started on some basic loops.
    Then it is what you must learn first!
    Victor Nijegorodov

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

    Re: input to determine even and odd numbers

    An even number is a number that is divisible exactly by 2 with no remainder. The modulo division operator % returns the remainder of the division.

    eg 7 % 3 gives 1 as 3 goes into 7 twice with a remainder of 1. Likewise 9 % 5 givers 4 etc.

    You will also need to be able to obtain the individual digits from the entered number so that they can be checked for being odd or even. The number can be either stored as an int and the digits extracted - or possibly easier in this situation - stored as a string.
    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)

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