Deepak and his journey


why this is not passing??

@shampblocks take your variable d as long long int cause when you multiply d with cost it will get stored in d and may cause int overflow.

i am doing typecasting at the time of multiplication and also my anser variable is long long int in this way why anser is not coming??

when you multiply two numbers and not store them anywhere it will get store in the data type of one of the variable hence that variable should be long long.

i am storing it in anser variable??

can you clear it???

@shampblocks you are storing it in anser when you add the result of (d*cost) to current anser.as per BODMAS they will multiply first but have you thought where is the result of that multiplication goes before adding it to anser.that is what i m trying to tell you.

So if I store it in another variable say x =cost×d and then add this x with my and it will work??

no it won’t, here you are copying the result of d*cost into x but before copying it will cause the same problem as above.

simply think that if you multiply (int*int) and the result is long long int then one of them should be long long int.

So what is the meaning of typecasting if it cannot be able to change one data type to another??

sorry i didn’t focus on why that typecasting is not working here,actually you have used wrong syntax for typecasting it should be like this
anser=anser+(long long int)d*cost;
giving braces there was causing problem

After doing this also anser was not coming?..

check carefully it should be working else send me your modified code.

@shampblocks if you still have any doubt let me know else mark this doubt as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.