What's wrong with this program?
I know that float accommodates 7 digits and double 15 to 16 digits but why this program show result with 5 digits as the default.
using namespace std;
The result is 3 with no digits.
The reason is the order of operation of the program
1. divide the two integers (10/3=3)
2. Cast the result to float (=3.0)
3. Store the result in a
As said before, there are to solutions
One is to cast one of the number or both to float
a=(float) 10 /3;
The operations are
1. Cast 10 to float (10.0)
2. Cast 3 to float, needed to make the division (3.0)
3. Divide 10.0/3.0 (=3.33333...)
4. Store the result to a
Or better put directly float numbers
1. Divide 10.0/3.0 (=3.3333)
2. Store the result into a