Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have 2 arrays one of the types of numbers that will be used and the 2nd array is how many times that number can be used. I have a letter that determines what kind of method will be used I need to figure out how many times I can use a certain number from an array to determine a letter+number The ‘number’ is what I have to make with all the available numbers I can use. If the number cannot be made I would like to just say number cant be made or anything but allow the program to move on.
Here is what I have
C#
int[] picks = { 100, 50, 20, 10, 5, 1 };
            int[] times = { 10, 10, 10, 10, 10, 10 };
string choice = Console.ReadLine();
else if (choice.Equals("D")) {
Dispense(amt, billCounts);
}


What I have tried:

I have the numbers working to use the next number if the current one is all used up i have all that working fine the only thing i have left is to stop the choice if there is not enough available picks to make a certain number
Posted
Updated 19-Feb-19 13:04pm
Comments
Richard MacCutchan 10-Feb-19 5:35am    
Why have you tagged this with so many different languages? Use the one that the code will be written in. You also need to show the code that has the problem.

1 solution

Dim Counts(5) As Integer = {0,0,0,0,0}
Dim tmpValue as Integer
Dim tmpMessage as string
Dim tmpTest as Boolean

' Initialise
tmpMessage = ""
tmpTest = false
tmpMessage  = ""
tmpValue = Choice

'Process
Do

   '// $100
   If tmpValue > 100 Then
      counts(0) = counts(0) + 1
      tmpValue = tmpValue - 100
   '// $50
   ElseIf tmpValue > 50 Then
      counts(1) = counts(1) + 1
      tmpValue = tmpValue - 50
   '// $20
   ElseIf tmpValue > 20 Then
      counts(2) = counts(2) + 1
      tmpValue = tmpValue - 20
   '// $10
   ElseIf tmpValue > 10 Then
      counts(3) = counts(3) + 1
      tmpValue = tmpValue - 10
   '// $5
   ElseIf tmpValue > 5 Then
      counts(4) = counts(4) + 1
      tmpValue = tmpValue - 5
   '// $1
   ElseIf tmpValue > 1 Then
      counts(5) = counts(5) + 1
      tmpValue = tmpValue - 1
   End If
Loop Until tmpValue < 1

'Finish
If Counts(0) <= 10 Then
   If Counts(1) <= 10 Then
      If Counts(2) <= 10 Then
         If Counts(3) <= 10 Then
            If Counts(4) <= 10 Then
               If Counts(5) <= 10 Then
                  tmpMessage & "This can be given in:" & vbcrlf
                  tmpMessage = tmpMessage & "   " & counts(0) & " $100 notes" & vbcrlf
                  tmpMessage = tmpMessage & "   " & counts(1) & " $50 notes" & vbcrlf
                  tmpMessage = tmpMessage & "   " & counts(2) & " $20 notes" & vbcrlf
                  tmpMessage = tmpMessage & "   " & counts(3) & " $10 notes" & vbcrlf
                  tmpMessage = tmpMessage & "   " & counts(4) & " $1 notes" 
               Else
                  tmpMessage = "Not enough $1 notes remaining in ATM"
               End If
            Else
               tmpMessage = "Not enough $5 notes remaining in ATM"
            End If
         Else
            tmpMessage = "Not enough $10 notes remaining in ATM"
         End If
      Else
         tmpMessage = "Not enough $20 notes remaining in ATM"
      End If
   Else
      tmpMessage = "Not enough $100 notes remaining in ATM"
   End If
End If

msgbox(tmpmessage)
 
Share this answer
 
Comments
Dave Kreskowiak 19-Feb-19 19:29pm    
Congratulations on trying to do the OP's homework for them. An unexplained code dump really isn't an answer.

Next time, don't. Doing someone's homework for them doesn't really help them at all.
Zaf Khan 19-Feb-19 19:32pm    
Thank you, now I know I will be careful next time.
Patrice T 19-Feb-19 20:16pm    
OP is also help vampire.
80+ questions so far
Richard Deeming 20-Feb-19 8:54am    
83, but that goes back to December 2013.

However, 41 of those have been posted since October 2018.

There also seem to be at least three versions of this question on the go.
Patrice T 20-Feb-19 11:41am    
I know, I gave a solution to 1 of the first versions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900