Math with decimals

How do I do to make it calculate "c" to 0,5 intead of zero?

code:
1
2
3
4
int a = 1;
int b = 2;
int c = a/b;
cout << "Result: " << c << endl;


Output:
Result: 0

Last edited on
You are using integers, which means that you can't have fractional parts of a number.
If you want fractional numbers, you must use the appropriate types.
1
2
3
4
float a = 1;
float b = 2;
float c = a/b;
cout << "Result: " << c << endl;

Hope this helps.
Thanks!
Topic archived. No new replies allowed.