hello I am working in a c++ problem and my answers should have decimals but when I compiled run the program it does not show any decimals
If you perform integer division then you get integer results only. For example int i = 5, j = 2; then if you ptint cout<<(i/j)<<endl; Then it prints 2 instead of 2.5. So, If you want result in decimal then just multiply expression with 1.0. For example cout<<(1.0*i/j)<<endl; This prints in decimal value 2.5 Or you can also cast the result to float. For example cout<<((double)i/j)<<endl; This also prints in decimal value 2.5
Get Answers For Free
Most questions answered within 1 hours.