I am trying to multiply two numbers
short totalSharesPurchased = 1024,
stockPurchasePrice = 39034.88,
stockSalePrice = 22374.40;
short gain_loss_amount = stockSalePrice - stockPurchasePrice;
I need the output 'cout' to show 2 decimal places. I think this is related to type of variables declared. Thoughts?
Thanks
You defined floating point numbers as integers of type short, So the numbers have no fractional parts. You should declare them as float or double.
I tried making float and double, then the math round up so instead of 39034.88 I get 39034.9 in the answer.
Last edited on
That looks good. New to c++ and in beginning class so have not leaned that yet but can not believe there is not a simpler way... Thank you!!!