Beginner in C++

Hi, and thanks for your help.

I'm trying to write a program that will prompt a user to enter an amount in the format of dollars and remaining cents in such a way that when a user is prompted to enter 5.37, it will give them the actual amount in quarters, pennies, etc.
This question may fit the Beginners section a bit better.

Last question for reference http://www.cplusplus.com/forum/general/229134/

Here's some javascript you can try out:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const availableChange = {
  hundred: 100,
  twenty: 20,
  ten: 10,
  five: 5,
  one: 1,
  quarter: .25,
  dime: .10,
  nickel: .05,
  penny: .01,
}

function breakMoneyIntoComponents(money) {
  const result = {};
  let remaining = money;
  while(Math.floor(remaining * 100) > 0) {
    for(key in availableChange) {
      if (remaining >= availableChange[key]) {
        result[key] = (result[key] || 0) + 1;
        remaining -= availableChange[key];
        break;
      }
    }
  }
  return result;
}


You can enter that into your developer console in your browser and paste that code then try out breakMoneyIntoComponents(1.27) to see the results
Topic archived. No new replies allowed.