I have created a program to display salarys, calculate a bonus payment and display total. Wages and total are my two arrays.
My problem is, when i run the program, my element starts at 0.i need it to start at one but it cant skip the first value in my array wages.

it is currently like this
0
1
2
3
4
5
6
7
8
9

i need it to display and the 10 salaries in there,it cant skip any.

1
2
3
4
5
6
7
8
9

public class Salary
{

    //main method

    public void calcSalary()
    {
        //My first array to store original salary
        //My second array is total[] to store total
        //Variables are bonus and my counter    

        double wages[]={56600,40000,30000,20320,10000,60000,35055,46000,23000,19000};

        final int TOTAL_LENGTH=10; //declare constant
        double total[]=new double[TOTAL_LENGTH];
        double bonus;
        int counter;


        //Prints out headings for my columns and my original salary and each person,0-9.


        System.out.printf("\n%s\t\t%s\n\n","REP","SALARY");

        for (counter=0; counter <total.length; counter++)

        System.out.printf("%d\t\t%.2f\n",counter, wages[counter]);


        //Sets my counter to zero and prints column headings

        counter=0;

        System.out.printf("\n\n\n%s\t%s\t%13s\n\n","REP","BONUS","TOTAL"); 


            //My while does the calculations and then displays the bonus in one column, and the total in another.
            //So long as my counter is less than total arrays length.

            while (counter<total.length)
            {


                //My if statements do the calculations to get the total based
                //On how much each person earns.

                if (wages[counter]<=19000)
                {


                    bonus=(double)wages[counter]/100*30;
                    total[counter]=(double)wages[counter]+bonus;
                    System.out.printf("%s\t%.2f\t\t%.2f\n",counter,bonus,total[counter]);


                }


                if (wages[counter]>19000 && wages[counter]<=40000)
                {

                    //Less than or equal to 40 k gets a 20% Bonus

                    bonus=(double)wages[counter]/100*20;
                    total[counter]=(double)wages[counter]+bonus;
                    System.out.printf("%s\t%.2f\t\t%.2f\n",counter,bonus,total[counter]);


                }


                if (wages[counter]>40000)
                {

                    //More than 40 k Gets a 10% Bonus

                    bonus=(double)wages[counter]/100*10;
                    total[counter]=(double)wages[counter]+bonus;
                    System.out.printf("%s\t%.2f\t\t%.2f\n",counter,bonus,total[counter]);


                }




                    //After each iteration, add one to counter

                    counter=counter+1;






            }//Ends my while



    }



 }

Edited 3 Years Ago by Nick Evan: Fixed formatting

You mean before my while statement does my calculation? That would mean it will skip my first value in my array wages and ignore it won't it?

Nope that messes it up . It has to have something to do with my array totals length

I meant like this:

System.out.printf("%d\t\t%.2f\n",counter + 1, wages[counter]);

and next time wrap your code between

tags so I can tell exactly which line I needed to point out

Edited 4 Years Ago by zeroliken: spelling error

No problem will do!

Yeah that worked perfect! So obvious no i look at it!! :(

Thanks very much i don't think i would have noticed that fair play

This question has already been answered. Start a new discussion instead.