creates Dictionary
added to the Dictionary value of currency
(1$,2$,5$,10$ and 20$) and the value the amount of those bills/coins in the
dispenser.
Lines 6-7 declare two variables, costArticle for the cost of the item to be
purchased and paymentClients to record the amount of the payment.
and paymentClients to record the amount that the customer entered.
Line 8 prints a question on the screen to request the price of the item to be
purchased.
Line 9 executes a conversion to convert the customer's answer to an integer and
store it in the variable costArticle.
in the variable costArticle.
In line 10 a second question is printed on the screen to request the amount entered
by the customer.
In line 11 a new conversion is executed to convert the customer's answer to a
decimal data and store it in the variable paymentClient.
and store it in the variable paymentClients.
Line 12 calculates the change requested by the customer by subtracting the cost of
the item minus the amount entered by the customer and storing it in the variable
paymentClients.
by the customer and storing it in the variable change.
Line 13 prints a sentence with the result of the calculation.
In lines 14-17 the total amount of coins/bills in the dispenser is calculated.
Line 18 verifies that the amount of change requested is less than or equal to the
total amount of coins/bills stored in the dispenser.
coins/bills stored in the dispenser. If so, it will print a message that there is
enough money available to give change.
available to make change.
Lines 19-20 create a new dictionary (returnedDechange) to store the change to be
returned to the customer.
Lines 21-64 control the amount of change to return to the customer. First it looks
for the highest value banknotes/coins and subtracts them from the amount of change
to be returned to the customer.
value bills/coins and subtracts them from the change amount, if there are enough
coins/bills in the dispenser,
then proceeds to perform the same process until the change amount equals 0.
Line 65 prints the change to be given to the customer.
Line 66 verifies if there is not enough money in the dispenser to give the change
to the customer, in which case it is printed.
to the customer, in which case a message will be printed telling the customer to
try a different amount.
// Input string
// Character counter with Dictionary
// We traverse the input string
// If the character already exists in the Dictionary, we increment the counter +1
// If it does not exist we add it to the Dictionary with counter = 1
// Output string
// Iterate the Dictionary to create the output string
// If there are more than two characters, we save them.
// If not, we print them without a counter
// Print the output string