15/4 equals 3?

Hi, I'm confused when the output given to me is 3, when I want it to be 3.75. I know if I do 15 %4 I would get a 3 but why would the following code also output a 3?
sorry if its an obvious answer


1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

using namespace std;

int main()
{
    float x;
    x = 15/4;
    cout << x;
    return 0;
}
closed account (48T7M4Gy)
Put a decimal point after 15 thus 15./4

http://stackoverflow.com/questions/7571326/why-cant-i-return-a-double-from-two-ints-being-divided
Last edited on
Topic archived. No new replies allowed.