Search code examples
c++integerdigit

How do I separate a 2 digit number into individual digits?


The program prompts the user to enter a 2 digit decimal number. How do I separate the number into two separate variables after the user enters it?

Later I need to use the first and the second part of the number so they need to be in different variables.


Solution

  • Start by dividing the number by ten, there you have the first number.

    int i = 99;
    int oneNumber = i / 10;
    

    You really should try to get the next one by yourself.