79699443

Date: 2025-07-12 17:05:20
Score: 0.5
Natty:
Report link

What is happening is that 120 and 77 are integers. When the operator/(int,int) function is performed, the return type is int. You either need to have a floating point type value (120.0 & 77.0) or you can typecast one of the values. The C-style typecasting is available and simple, by placing the type to be casted as in parenthesis.

float num = (float)120/77;

However, in C++, static_cast<T>(T) is preferred. Also, I would recommend using double instead of float.

double num = static_cast<double>(120) / 77;

Typically, casting is done for variables and not hard-coded values.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): What is
  • Low reputation (1):
Posted by: Matthew Osborne