Assume that type Money, a structured type with two int fields, dollars and cents, has been declared . Write the definition of a function named normalize that receives a Money argument and returns a Money value. What it returns is the “normalized” equivalent of the argument, that is, a value that is equivalent but where cents is a number between 0 and 99 inclusive. So if a Money value of 5 dollars and 325 cents was passed, a Money value of 8 dollars and 25 cents would be returned.

LANGUAGE: C++

CHALLENGE:

Assume that type Money, a structured type with two int fields, dollars and cents, has been declared . Write the definition of a function named normalize that receives a Money argument and returns a Money value. What it returns is the “normalized” equivalent of the argument, that is, a value that is equivalent but where cents is a number between 0 and 99 inclusive. So if a Money value of 5 dollars and 325 cents was passed, a Money value of 8 dollars and 25 cents would be returned.

SOLUTION:


Money normalize (Money unNormalized){
    unNormalized.dollars = unNormalized.dollars + unNormalized.cents/100;
    unNormalized.cents = unNormalized.cents % 100;

    return unNormalized;
}