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

Assume you are given a variable, payRate of type Money (a structured type with t

ID: 3641832 • Letter: A

Question

Assume you are given a variable, payRate of type Money (a structured type with two int fields, dollars and cents). Write the necessary code to increase the effective value of payRate by $1.50. To do this you need to add 50 to cents and 1 to dollars but you ALSO must make sure that cents does not end up over 99: if it does, you need to "carry a one" to dollars. For example, if payRate were $12.80 then a naive addition of $1.50 yields 13 (dollars) and 130 (cents). This would have to be changed to 14 (dollars) and 30 (cents).

Explanation / Answer

payRate.dollars += 1; payRate.cents += 50; if(payRate.cents >= 100) { payRate.cents -= 100; payRate.dollars += 1; }

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