algorithmcoin-change# Algorithm for the least amount of change

Yes I know there has been similar posts to this however after looking through them all I'm still stuck as I'm very new to programming and none of the answers given were specific enough to my problem to help.

Question. Write an efficient ACL (algorithmic computer language) algorithm that, given a cost of an item (less than or equal to one dollar), gives the number of 50 cent, 20 cent, 10 cent, 5 cent and 1 cent coins the buyer would receive if they handed over one dollar. You must minimise the number of coins in the change.

The question is not related to any specific programming language, and the answer can only use simple ACL language like if, if-else, while loops and can't use arrays or other advanced commands.

Here is where I am at:

Algorithm minimum amount of change

```
{
int cost, fifty, twenty, ten, five, one;
fifty = 0;
twenty = 0;
ten = 0;
five = 0;
one = 0;
read (cost);
if (cost <= 50)
{
fifty = 1;
```

Finished code, thankyou for your help! If you can see any ambiguities or can help me simplify the code please let me know.

```
Algorithm how much change
{
int cost, change, fifty, twenty, ten, five, one;
fifty = 0;
twenty = 0;
ten = 0;
five = 0;
one = 0;
read (cost);
change = 100 - cost;
if (change >= 50)
{
fifty = fifty + 1;
change = change - 50;
}
while (change >= 20)
{
twenty = twenty + 1;
change = change - 20;
}
while (change >= 10)
{
ten = ten + 1;
change = change - 10;
}
while (change >= 5)
{
five = five + 1;
change = change - 5;
}
while (change >= 1)
{
one = one + 1;
change = change - 1;
}
print(one, five, ten, twenty, fifty);
}
```

Solution

actually, cost >= 50 need to be checked only once, but this is more generic (for cases over 1 dollar)

```
while (cost >= 50)
{
fifty++;
cost -= 50;
}
while (cost >= 20)
{
twenty++;
cost -=20;
}
...
```

- How to generate uniformly distributed subintervals of an interval?
- Generating random number in a non-power-of-2 range from random bits
- Algorithm - Search and Replace a string
- Looking for a branchless algorithm for converting a specific set of 4-bit integers
- Different results for XIRR between Excel and ExcelFinancialFunctions 3.2.0
- Find four,whose sum equals to target
- A* algorithm can't find the goal in Python
- Efficiently getting all divisors of a given number
- Are there any existed API to split IEnumerable<T> to many Vector<T> in CSharp？
- Generating all divisors of a number given its prime factorization
- Efficient way to insert a number into a sorted array of numbers?
- BFS Maximize Minimum Distance from a Monster along a path
- Is there effective algorithm that will return all different combination?
- Big O of algorithm that steps over array recursively
- Modification of Dijkstra's algorithm to make it work with negative weights and its time complexity
- Traversing/Moving over an unfolded cube
- Fibonacci Recursion using Golden Ratio(Golden Number)
- Karatsuba implementation in C
- Why is O(n) better than O( nlog(n) )?
- What is Sliding Window Algorithm? Examples?
- How to write a function to navigate through a non-binary tree?
- Evenly distribute QDate values into certain number of slots
- Find max product using divide and conqure in O(n) time
- Cache-friendly sqare matrix transposition logic issue
- Why doesn't Dijkstra's algorithm work for negative weight edges?
- Fast Convertion From Adjacency List to Edge List
- I convert ASCII words into numbers but am stuck trying to decode them. How to convert 1=a, 2=b, 28=ab etc? (psudeocode okay)
- Reversing the word order in a string in place
- Trying to make a 2x2 rubik's cube solving algorithm , how do i find the solution path (DFS)?
- question about missing element in array