0

How do I get a decimal value in c++?

I've defined everything as floats that need to be but I still can't get it to output a decimal value could someone please explain why and maybe provide a solution? https://code.sololearn.com/cCUGvQt00x01

22nd Mar 2018, 5:55 PM
Type
Type - avatar
4 odpowiedzi
+ 2
What is the exact input you're giving the compiler? If you enter the number for money with the only punctuation being the '.' for the decimal portion, it should work correctly. By that I mean, enter "98765.45" instead of "98,765.45" (don't use a comma). I noticed the comma made the compiler read the above number as only 98; thus, the reason why it wasn't printing any decimal with the number. I agree, you should use the appropriate types (float/double) for your variables to avoid loss of precision. And I agree with Martin that you should return a float from your interest function. Here's what I would change with your code: https://code.sololearn.com/craBf6t7Z5ta I changed variable names with my best guess as to a good name to represent them. I noticed some things I needed to change in my edit of your code so feel free to take another look.
22nd Mar 2018, 10:37 PM
Sam
Sam - avatar
+ 1
Simply use float instead of int while declaring variables.. Please give an upvote it will earn me a badge
22nd Mar 2018, 7:00 PM
Anand Mishra
Anand Mishra - avatar
+ 1
Thanks everyone totally missed the function returned int!
23rd Mar 2018, 5:13 AM
Type
Type - avatar