Predefind Function

Is there a predefined function that take the first two digits
of a number such as 2008 and divide it by a number. I am working on a program that is asking this function: int getCentury(int year) to take the first two digits of the year, divide and save the reminder.

Thanks.

1
2
3
4
5
6
int highestTwoDigits(int x)
{
    while( x>=100 )
        x /= 10;
    return x;
}


simple enough ?

EDIT- edited the condition.
Last edited on
Thanks. I assume ,after division, I also have to use the floor function to eliminate the digits after decimal point
like

floor(20.08)
will result to 20.
int doesn't have digits after the decimal point so it is not necessary.
Thanks. I totally forgot about that. Also how can I find list of all C++ predefined functions in
this website?.
Last edited on
You can use google to check for specific libraries :) C++ itself doesn't have much functions, headers that you are including have. Type their name in google, you will see all functions. Or, go to reference page - http://www.cplusplus.com/reference/

And try to check for yourself before asking next time. Cheers!

to take the first two digits of the year, divide and save the reminder


1
2
3
4
5
6
int highestTwoDigits(int x)
{
    while( x>=100 )
        x /= 10;
    return x;
}


@rechard: i don't think it's the right answer

@op: maybe you can use string for more flexibility

CMIIW
Topic archived. No new replies allowed.