| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Selecting certain part on an entry.
Hello!
I'm really new to C++ and I want to write a simple program, that would proccess entered number part by part, but I can't figure out (nor could I find anything on the subject) how to make my program do it. For example, it should look like this: Enter code: 32101243421 if <first two digits> < xx, then xx if <third and fift digit> > xx, then xx if <sum of all digits> > xx, then xx. etc. Thanks in advance. |
|
#2
|
|||
|
|||
|
Off the top of my head, I'd suggest reading about the modulo operator which is useful for getting the value of each digit. To shift a decimal number 1 digit to the right simply divide by 10.
Code:
int number(121123); int nextDigit(0); nextDigit = number % 10; // nextDigit becomes 3 number /= 10; // number becomes 12112 |
|
#3
|
|||
|
|||
|
Re: Selecting certain part on an entry.
Thanks!
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|