I dont know how to get the numbers to show up on the side but this is my program for counting coins and this is the error i keep getting
[Warning] converting to `int' from `float' on line 20(N2=N1*100)
How would I fix this issue? The program works sometimes but there are rare occasions where it will round a number down (like i would take 167 and make it it 166) and it is throwing off the rest of the calculations.
Pleas use the code tags - the <> button on the right.
You are getting this error because N2 is an int on the left side of the assignment, so it has to convert whatever the answer is (of type float)to an int.
However you need ints to do the remainder calcs.
So the answer is to use ints where needed, then cast them to double once the remainders have been calced.
Hang on ..... N1 is already a float, N2 is an int - so that is the original problem.
The OP could do C casting with an int:
N2 = (int)N1 * 100;
This is OK logically because the multiplication has converted to cents already - the explicit cast should remove the warning.
I think if the OP names the variables better there might not be as much confusion - there are logical errors in which variables are being used for which calculation.
HTH
Edit:
I mentioned the static_cast because that seems to be the C++ way of doing things.