0

I have this code:

    /* For loop to count 50 days */
    for (int n = 1; n <= 50; n++) {

        int solve = 0;
        solve = solve++;  
        item_1.removeDailyDemand();

        if ( n % 5 == 0){


        }
        if (solve == 5){

            item_1.isReOrderPoint();
        }

        System.out.print(n + "\t");
        System.out.println (item_1.getQuantityInStock() + "\t");

Been playing around for ages, very new to Java. I just want it to increment "solve" as it does "n" whilst running the for loop.

Been trying most the day and no results!

Thanks

Liam
  • 93
  • 2
  • 13

2 Answers2

1

Replace:

/* For loop to count 50 days */
for (int n = 1; n <= 50; n++) {
    int solve = 0;
    solve = solve++;  

By:

/* For loop to count 50 days */
int solve = 0;       
for (int n = 1; n <= 50; n++) {
    solve++;  

In each iteration you reset you solve variable to 0. And solve = solve++ is useless because first you copy the solve variable then you increment it. The same as solve++

Ludovic Feltz
  • 11,416
  • 4
  • 47
  • 63
1

You are declaring the solve to zero every time inside the loop:

/* For loop to count 50 days */
int solve = 0;
for (int n = 1; n <= 50; n++) {
    solve += 1;  
    item_1.removeDailyDemand();

    // same as your previous code
}

Or on similar lines you could use:

/* For loop to count 50 days */
int solve = 0;
for (int n = 1; n <= 50; n++, solve++) {
nitishagar
  • 9,038
  • 3
  • 28
  • 40
  • It's not working, it's still displaying the message on every "n" occurrence ` int solve = 0; /* For loop to count 50 days */ for (int n = 1; n <= 50; n++) { solve++; item_1.removeDailyDemand(); if ( solve == 1);{ System.out.println("Order Made"); } Thanks – Liam Dec 08 '14 at 18:34
  • Can you paste the whole thing (modified code). – nitishagar Dec 08 '14 at 18:49