0

I am writing a program about giving change. But I am having issues with getting remainders for decimal numbers.

For instance I am giving $46.63 change

I want to know how many $20.00 bills it has, I would have to divide it by 20.

46.63 / 20 = 2.3315

My question is how can I get the .3315?

The problem is that % does not work with double, I tried it with integer, but I just can't get the cents.

3
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by Ancient Dragon
1

so convert everything to cents
multiply up by 100 convert to int, use %, then convert results back to double

Edited by frogboy77: n/a

Votes + Comments
Exactly!
0

so convert everything to cents
multiply up by 100 convert to int, use %, then convert results back to double

Multiply the $46.63 by 100 that's what you mean.

Would it be like this 46.63 * 100 % 20?

46.63 / 20 = 2.3315

0

No. double x=23.56
x*=100
iny y=(int)x
then use %

I am trying to figure how the code works, but I still don't get it since I am beginner in programming.

Did you mean?

double x = 46.63; That's the value that was given.
x = 100;

int y = (int)x; then use %.

I've been trying numerous time to covert int to double, I always get an error in the code.

0

ok x=46.63
x = 100 * x // same as x*=100 ie x now equals 4663
google casting in c++
then work on ints using modulus

edit: the number i used was just random

Edited by frogboy77: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.