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);
7 Years
Discussion Span
Last Post by JamesCherrill

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.