Methods for Creating a function that reads digits of any number

Here is the RME:

//Requires: num >= 0; 0 <= digit <= 9
//Modifies: nothing
//Effects: will return true if 'digit' occurs anywhere within 'num'
// returns false otherwise
// if num=42 and digit = 5 this will return false
// if num=42 and digit = 4 this will return true
// if num=142 and digit = 2 this will return true
bool equalsDigit(int num, int digit);

Is there a way in which I could read in each digit in num separately, so that I can check those with the digit input. Unless there is another way that you may have. Please do not create the whole function for me, I have to do that on my own.

Thank you!
% and / are your friends here.

Dividing (/) a number by 10 will drop the last digit.

Modding (%) a number by 10 will isolate the last digit


Mod gives you the remainder after division. So for example, 15 % 7 would be 1, because 15/7 is 2 remainder 1.
Excellent! Thanks.. haha easy.
Topic archived. No new replies allowed.