Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

For example: double amount, remnant; int number; number = (int)amount/50; remnant = ((int)(amount*100)%5000)/100.0; My question is how do we know that we need to add int to the operand?

OpenStudy (anonymous):

In the first assignment, you are assigning a double to an int variable, so (at least in C++ and some other languages) you will need to cast the expression to int. In the next assignment, you are using the modulo operator, so you will temporarily cast the value of the (amount*100) expression to int to carry out the operation..

OpenStudy (anonymous):

and when you divide in second expression by double (decimal separator shows it's double) then previous int is automatically converted to double so you don't need to use (double)

OpenStudy (anonymous):

right, in such operations the operands are usually implicitly converted to the proper datatype

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!