#include
using namespace std;
int main(int argc, char** argv){
float result;
result=(340/101);
cout<<\"Result=\"<
In C++, the (340/101)
is considered in isolation. Since both operands of /
are int
s, the compiler generates code for integer division. Then, since you're assigning that result to a float
, it generates code to convert the resulting int
to float
.
To get floating point division, you need to ensure that (at least) one of the operands to /
starts out as a float
(or double
), such as: float result = 340.0f / 101.0f;