Hi everyone, I am really new to this, in fact I only installed the compiler today. I am reading the tutorials but have become stuck when trying to do some simple addition. I cannot get my small piece of coding to add numbers with a decimal place.
Thanks Dukaim for the reply, changed the code to this, sorry to be a pain but I now get a compiling error "Illegal use of decimal point" what do you think?
I am just trying to add numbers and divide numbers. Whole numbers work but using numbers with decimal places doesn't, I was expecting the answer to be 6 for all three sums, I am just playing around with code to see how it works and try to understand it thanks.
I know what you mean, there is a tutorial at http://www.cplusplus.com/doc/tutorial/operators/
which shows three sums at the bottom of the page it says all the sums should give the same result, I put the sums into the code just to test them out, which is when I got problems, I have done the same thing again only not used division, just simple + - and it works no problem, both the % and the / symbol don't seam to work as expected.
I don't think you can use the % operator (normally, at least) on non-integer numbers. In the tutorial, all the numbers that the % operator is applied to are integers.
Even though % (modulo) means remainder of division, it is commonly thought of in this manner: X%Y, where it tries to see how many times it can subtract Y from X before Y is less than or equal to X. This is essentially an alternative thinking style, and while correct people often forget that it is still the same as remainder of division, and thus cannot be used the way they expect with floats. You can just make a function for it though, if you want the alternative thinking style. ;)