Hi everyone, basically the problem i have is; when the program loops around for the 2nd, 3rd etc it resorts the swip back to the inital value of 1000, rather than what i want it to, the ewip from the previous day. I have underlined/highlighted the two bits i mean. For example after the first loop Ewip =5, then i want the swip for the next day to equal this number rather than 1000

int x = 0;
while (x < 10)
{ x++; //Loops 10 times


int endwip, sentnum, counter;

int startwip = 500;//Given it a value higher than can be taken
counter =0;//Given it a value otherwise system thinks it won;t be initialised
Random dice = new Random();
for(int counter=0; counter<1;counter++){
counter= 1+dice.nextInt(6);} //Creates a random number to be passed along

workstation ws = new workstation(number);
sentnum=counter;//Sent numner = Dice roll
endwip= startwip -sentnum; //Calculates the EWIP, which will be the next turns SWIP
startwip = endwip-counter;//Give the SWIP a value for the next turn
System.out.println("new swip " + swip);
}
}

Which loop? The i=1..10 or the baffling counter one on lione 12 (that looks like it will only ever be executed once). If it's the first loop, you need to declare and initialise the varaibles (lines 6 & 8) outside the loop, ie before line 2.

yer the variables above the loop works for that workstation, however i have anther 5 workstations below that need to do the same principal, and can't have them above the loop.

Is there any way to solve it or do i have to rewrite the whole code somehow :s

Sorry, I don't know what you're trying to achieve overall, so I can't comment on overall code design.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.