Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a function called lastValues that will produce the last two values in an

ID: 3873379 • Letter: C

Question

Create a function called lastValues that will produce the last two values in an int variable. Your function should take as parameters the integer to extract the last two values from, and two int variables passed by reference to hold and produce the last two values extracted. Your function should check to make sure that the int has at least two digits in it. If it does not your function should simply return false. If it does extract the last two digits, store them in the two reference variables, and return true.

NOTE: You are not allowed to convert the number to a string in any way. You must compute the last two values using the math operators.

Explanation / Answer

/*num is the input integer
secondLast and last are pointers for second last digit and last of num respectively.
*/

bool lastValues(int num, int* secondLast, int* last)
{
           //if input num is negative then removing minus sign
            if(num < 0)
                        num = num * -1;
            //check input integer has atleast two digits
             if(num < 10)
                         return false;


            //finding last digit of num
             *last = num % 10;
             num = num / 10;
             //finding second last digit of num
             *secondLast = num % 10;
             return true;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote