# code help

• 10-06-2011, 09:37 PM
andnlou2678
code help
hi i have got this code and i got it to equal 2000 but i need it to equal 1000 can somebody please help me

many thanks..

/calculate and output half of my savings
public class Savings
{
//your share is 50% of my savings
public static void main (String args[])
{
int mySavings = 2000;
int yourPercentage = 50;

int yourShare = (mySavings + (yourPercentage / 100));

}
}
• 10-06-2011, 10:01 PM
sunde887
Re: code help
Multiplication is used to find a percentage of some number, not addition.
• 10-06-2011, 10:26 PM
andnlou2678
Re: code help
i put in * m8 and i got an answer of 0?
• 10-06-2011, 11:29 PM
Golfnutest
Re: code help

int yourShare = (mySavings + (yourPercentage / 100));

with:

int yourShare = (mySavings * (yourPercentage / 100));

your code should produce 2000.5 This code produces 1000.

Golfnut
• 10-06-2011, 11:47 PM
andnlou2678
Re: code help
//calculate and output half of my savings
public class Savings
{
//your share is 50% of my savings
public static void main (String args[])
{
int mySavings = 2000;
int yourPercentage = 50;

int yourShare = (mySavings*(yourPercentage / 100));

}
}

this is the code and i am still getting 0 as my answer
• 10-07-2011, 12:18 AM
milovan
Re: code help
A hint:

what is an Integer from 50 / 100?
• 10-07-2011, 04:02 AM
Golfnutest
Re: code help
Duh. Not sure if this would be the preferred way to go about this, but this works:

double mySavings = 2000;
double yourPercentage = 50;
double yourShare = mySavings * (yourPercentage / 100);

`(double) 5 / 2;`