smc18
March 14th, 2008, 02:27 AM
Hi, I am stuck with some math, I'm not sure if I just need to format the output or if there is a problem with something else.
Here is an excerpt of the code,
sum = 3/15;
cout << sum << endl;
will just return a value of 0.
or
sum = 3/15 + 2;
cout << sum << endl;
will return a value of 2
However the code,
sum = 10 + .5;
cout << sum << endl;
will return a value of 10.5
Why is 3/15 returning a value of 0?
I'm programming this on a Windows machine, using Dev-C++, I have included
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
and declared sum as a float data type, not an int. Any help is appreciated, thanks. If you need more information please just ask.
Here is an excerpt of the code,
sum = 3/15;
cout << sum << endl;
will just return a value of 0.
or
sum = 3/15 + 2;
cout << sum << endl;
will return a value of 2
However the code,
sum = 10 + .5;
cout << sum << endl;
will return a value of 10.5
Why is 3/15 returning a value of 0?
I'm programming this on a Windows machine, using Dev-C++, I have included
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
and declared sum as a float data type, not an int. Any help is appreciated, thanks. If you need more information please just ask.