What is the most efficient way to get the last 2 digits of an integer into a seperate variable? What about the 3rd and 4th last?
Ex.
123456
int a should == 12
int b should == 34
int c should == 56
What is the most efficient way to get the last 2 digits of an integer into a seperate variable? What about the 3rd and 4th last?
Ex.
123456
int a should == 12
int b should == 34
int c should == 56
You can use the modulus operator to get the remainder of a division operation. If you divide a number by 100, the remainder is going to be the last two digits of that number.
Getting the third and fourth is a very similar process. Get the last four digits, then divide by 100 (integer division just drops the remainder in C++) to get the first two.
Great! Thanks.
In case you were wondering, this isn't homework. I'm still in high school. This is for my own personal health.