Basic program not recognizing float

Hi all, I'm using float for the first time and am running into trouble.

Here's a snapshot of the code:

1
2
3
4
5
6
float fl = 1.00;
cout << fl;
int a = 10;
int b = 5;
fl = b/a;
cout << fl;


The output is "1 \ 0" when I am expecting "1.00 \ 0.50". Please let me know where I went wrong. I was not able to find a good example of basic input combined with basic calculation on the forum. Thank you!
Dividing two ints will return an int. So 5/10 will return 0.
To calculate floats, simply cast one of the ints to a float:
1
2
3
f1 = float(b) / a;
//Or...
f1 = static_cast<float>(b) / a;
That's it! Thanks so much for the quick reply.
Topic archived. No new replies allowed.