automatic conversion of int, float, etc.
Today the instructor marked the following line of the code wrong (I have shorten it):
He said that you are adding up different data types which is not correct. You must first convert 'float a' into an int.
int d = float a + int b + int c;
In the past I have several times written things like:
He didn't tell me then that I was wrong. I believe the compiler takes care of such small details and automatic conversion takes place.
float a = b / 10;
Now see this code from a book:
I don't see there was real need for casting 'dumintpart' into float because it will automatically will be converted into a float to do the subtraction from 'dumnumber' which is a float. Please let me hear your opinion. Thank you.
void intfrac(float dumnumber, long& dumintpart, float& dumfracpart)
long temp = static_cast<long>(dumnumber);
dumintpart = temp;
dumfracpart = dumnumber - static_cast<float>(dumintpart);
EDIT: I have made an edit; it appears in orange.