Integer Division, and the Cast That Undoes It

Easy

Read two ints from standard input with a single scanf call, then report the same division three ways: as an integer division, as a real division obtained by casting one operand to double, and as that double stored back into an int. Declare total as an int initialized to 0 and parts as an int initialized to 1, because parts is about to be a divisor and dividing an int by zero is undefined behaviour. Print scanf's conversion count first, then the three results. Watch what happens on the negative input: both truncations discard the fractional part rather than rounding, and they discard it toward zero, so -3.5 becomes -3 and not -4.

Success Criteria

Your code must pass 3 test case(s) to complete this exercise. 3 hint(s) are available if you need help.

Sign in to track your progress

You can work on exercises as a guest, but sign in to track your progress and save your submissions.

This platform is built by its community

Every lesson, project, and tool on HelloC++ is funded by sponsors. Join them and help shape what we build next.

Become a Patron