Having Trouble figuring out what went wrong in my mixing milk code

Problem Info

Add name of problem + link to problem here
USACO BRONZE #1- Mixing Milk USACO

My Work

Add commented code here
import java.util.*;
import java.io.*;
class Main {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int ac = input.nextInt();
    int a = input.nextInt();
    int bc = input.nextInt();
    int b = input.nextInt();
    int cc = input.nextInt();
    int c = input.nextInt();
    int numofmixed = 0; // initializing the variables for each bucket and their capacities.
    

while(numofmixed<=100) { // the pours themselves 
      mix(a, ac, b, bc);
      mix(b, bc, c, cc);
      mix(c, cc, a, ac);
      numofmixed+= 3;
    }
    System.out.println(a + " " + b + " " + c);
    }
    
public static void mix(int currentamount , int capacityrn, int nextamount, int capacityofnext) {
    while(currentamount >= 0 || nextamount<= capacityofnext) {
      currentamount--;
      nextamount++;
      // method to calculate a pour//
    }
      }
        }

Add explanation of code here
So essentially i’ve tried solving this problem using a method in which for each pour i take one “milk” away from the original bucket and add it to the new bucket up until there is 0 in the original bucket or there is maximum milk in the next bucket. Then i looped through all the 100 pours using my method.

What I’ve Tried

Ive tried using the sample input and output to test my solution but so far all my code outputs no matter what i change is “3 4 5” which is the incorrect output.

Question

If someone could help me understand what I’m doing wrong for this problem I would really appreciate that. Thanks :slight_smile:

Checklist

See How to ask for help on a problem for more information.

  • Include a link to the problem
  • Format your post (especially code blocks)
  • Include what you’ve tried so far
  • Add comments to your code
  • Read the debugging module

The function mix doesn’t change a, b, or c.

1 Like

How would i be able to fix that so that it changes a b and c?
Thanks

I think you should return currentamount and nextamount, then replace a, b, and c with the corresponding amount.

what do u mean by replace a, b, and c with the corresponding amount?

like return currentamount,nextamount, then a=currentamount, b=nextamount

but then it wouldnt do all 100 pours right?

replace a, b, and c with the amount of milk after the pour

could u send me the code of what ur talking about im a bit confused.
Sorry

I think this works

public static int[] mix(int currentamount , int capacityrn, int nextamount, int capacityofnext) {
    while(currentamount > 0 && nextamount< capacityofnext) {
      currentamount--;
      nextamount++;
    }
    int[] l = new int[2];
    l[0] = currentamount;
    l[1] = nextamount;
    return l;
    
      }
        }

then when you do mix(a,ac,b,bc), replace a with mix(a,ac,b,bc)[0] and replace b with mix(a,ac,b,bc)[1]

when you do x = mix(b,bc,c,cc), replace b with x[0] and c with x[1], and do the same thing for mix(c,cc,a,ac)

kk ill try this.
Thanks :slight_smile:

there’s also a slight problem with your loop. it does a total of 102 pours instead of 100

wait but then there are multiple outputs
we get the result of every pour
but the problem only wants the last one

then just print the last pour