Hello, CPlusPlus community. Thank you in advance for you assistance. I'm a computer science novice and am struggling heavily with the concept of arguments, return values, function prototypes, and function calls. I took 190 last year and am taking my second course 226. This function stuff is pretty heavy!
I am having major trouble understanding where I went wrong in this? I apologize for lack of the //comments.
As josue mentioned any integer divided by an integer is an integer.
You must either do a floating point divided floating point , floating point divided by integer or integer divided by floating point to get a return of a floating point.
ex:
1 / 2.0
1.0 / 2
1.0/2.0
1 / 2f
1f / 2
1f / 2f
Well think about it are integers rational or irrational numbers?
Here is a better explanation.
1 2
intoperator/( int , int )
floatoperator/( float , int ) // not sure if it is float or double by default
That's how the operator/ is overloaded AFAIK.
Just rememeber int + int = int
int * int = int
int / int = int
int - int = int
Since irrational anything irratonal = irrational
but if you put a rational anywhere then it has to be rational since 1 + 1.2 will be equal to 2.2 and not 2
Well, I do admit that the plethora of ways of skinning the cat can become overwhelming; in addition to what giblit said, you can also cast one integer and let the compiler coerce the other (or cast both!) this way: