int first2_digit(vector<vector<int>> number, int win)
{
int first_digit;
if ( number.size() % 2 == 0) // number of digit is even
{
do {
first_digit = win % 100;
win /= 100;
} while (win > 0);
}
else{ // number of digit is odd
do {
first_digit = win % 1000;
win /= 100000;
} while (win > 0);
}
return first_digit;
}
My code has problem with odd number of digit
For example: if the input number is 12345, the output will be 1 instead of 12
#include <iostream>
int main()
{
std::cout << "enter an integer: " ;
int n ;
std::cin >> n ;
if( n < 0 ) n = -n ; // ignore the sign
// keep chopping off the rightmost digit, till only two digits remain
while( n > 99 ) n /= 10 ;
std::cout << n << '\n' ; // print the result
}