Ten problems with real numbers — divisions, square roots and answers with a fractional part.
- At least one side of a division has to be a
doublebefore it happens:1.0 * a / b, nota / b. - Some inputs are fractions themselves, like
1.5— read them into adouble. - Watch for whole-number division hiding in a formula —
2 / 5is 0 — and for squares of big coordinates: keep them inlong longordoublebeforesqrt. sqrt(x)gives a square root as adouble;absgives a distance.- When the output asks for a number of decimal places, print with
cout << fixed << setprecision(k) << x;, wherekis how many.