Consider the following:
int num = 5;
double total = num / 2;
Is it correct to say that the quotient of num / 2 is not a double because you need to parse the int to double?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The technical answer is that the
/operator produces an int when given two ints. This computation is done independent of its assignment to adoublevariable.You actually do get a double value in the variable
total, but it is 2.0, not 2.5. The integer 2 is cast to 2.0 in the initialization.Your options, if you want 2.5, are:
In short, it is not a parsing issue, but rather one of C++ operator semantics. Hope that made sense.