0

how this code prints 0

#include <iostream> using namespace std; int main() { float area; float a=5; float b=10; area=(1/2)*a*b; cout <<area; }

2nd Apr 2019, 8:48 AM
Shahanshah
Shahanshah - avatar
3 Respostas
+ 6
Maybe write 0.5 than 1/2?
2nd Apr 2019, 8:55 AM
Николай Шаповаленко
Николай Шаповаленко - avatar
+ 4
1/2 are integers, so the result is 0. So you wrote: 0*a*b. Change the beginning to (1.0/2)!
2nd Apr 2019, 8:52 AM
HonFu
HonFu - avatar
+ 2
Or that.
2nd Apr 2019, 8:55 AM
HonFu
HonFu - avatar