Hey, I have a little question about division of two numbers.

For example, if a user enter these two numbers : 30 and 40

30/40=0,75

How can I make my programm show the whole decimals and not only the 0 ?

Because this is the kind of result I get :

30/40= 0

How can you change this ? Thank you !
That is integer division. The reason is that 30 and 40 are integer literals. If you want to do a floating-point divide, at least one of the values must be a floating-point type.

Any of these should work:
30.0 / 40.0
30 / 40.0
30.0 / 40

However, if the user enters these values, then the variable which receives the input must be of a suitable type (double or float) instead of int.
Last edited on
You are dividing ints and so the floating point data is thrown away. Use either floats or doubles.

 ``12345678`` ``````#include int main() { double num1, num2; std::cin>>num1>>num2; std::cout<

This should work
@chervil
you can also do
30f / 40
30 / 40f
30f / 40f
Topic archived. No new replies allowed.