Hi
Today the instructor marked the following line of the code wrong (I have shorten it):
Code:
int d = float a + int b + int c;
He said that you are adding up different data types which is not correct. You must first convert 'float a' into an int.
In the past I have several times written things like:
Code:
int b;
float a = b / 10;
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.
Now see this code from a book:
Code:
void intfrac(float dumnumber, long& dumintpart, float& dumfracpart)
{
long temp = static_cast<long>(dumnumber);
dumintpart = temp;
dumfracpart = dumnumber - static_cast<float>(dumintpart);
}
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.
EDIT: I have made an edit; it appears in orange.