I need everything to come out as a double rather than an int. I dont know how to do this other than creating lots of variables! Is there a way i can convert? my counter is causing the problem but i dont think theres another way to do it.The program simply prints 10 peoples wages, in an array, then it prints the bonus based on a per cent, then the total inc bonus!! and stores the new total in a new array, called total[]. .....any help would be appreciated

``````public class Salary
{

public void calcSalary()
{

int wages[]={50000,40000,30000,20000,10000,60000,35000,46000,23000,19000};

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

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

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

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

counter=0;

while (counter<total.length)
{

if (wages[counter]<=19000)
{

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

}

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

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

}

if (wages[counter]>40000)
{

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

}

counter=counter+1;

}

}

}
``````

## All 8 Replies

1. You should have posted in the Java Forum for experienced Java users to see this post
2. Why make a duplicate thread about the same problem with your last thread?
3. Are the suggestions in the other thread not helpful?

@ zeroliken: thank you

i didn't get any suggestions of use, im not sure how to delete a thread , if you know you could tell me and i will.

well AFAIK even if you convert the values to double You can't store them in an int variable

my counter is causing the problem

which variable are you talking about?

i need all the data in my array wages[], total[] and my bonus variable to be doubles.The problem is, i need to use my counter as an int , and i need it as it calculates the totals for me, i need a way of getting around this, rather than just creating lots of different variables. I cant calculate with an int and a double together thats my issue

ok so i change all my variables to double. Ive done that, but my counter is still causing the issue as i cant change that to double or it wont work

``````System.out.printf("\n%s\t%11s\n\n","REP","SALARY")
System.out.printf("\n\n\n%s\t%10\n\n","BONUS","TOTAL");``````

These are wrong, the arguments used here are not variables

1.Initialize the variables bonus and total array as double(no need to change variable counter as a double)
2. use %f at the printf statements for the variables which are double
3. use these for precision

``````bonus = (double) wages[counter]/100*30;
total[counter] = (double) wages[counter]+bonus``````

4. use code tags next time

You're right it works! i had the double in brackets before the equals as in

(double)bonus = wages[counter]/100*30;

Thank you very much It was seriously annoying me at this stage!! Im new on here so not sure about the correct way of posting and whatnot im sure i'll learn! Thanks again!

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.