# Thread: Sum of 4 numbers...!?

1. Member
Join Date
Feb 2010
Posts
5
Rep Power
0

## Sum of 4 numbers...!?

Hi everyone

I've a project to do,and i need some help.The project is "We have to add as input a double and than the input number must express as sum of four other numbers.It's analogy of monies.For example let's say we have €48.5 and we have to seperate this as sum of monies as 5€,3€,2€,1€ and cents".Hope that's clearly explained.
Regards

Hi everyone

I've a project to do,and i need some help.The project is "We have to add as input a double and than the input number must express as sum of four other numbers.It's analogy of monies.For example let's say we have €48.5 and we have to seperate this as sum of monies as 5€,3€,2€,1€ and cents".Hope that's clearly explained.
Regards
Very clearly. What's not explained however is your specific question. What have you done so far? Where exactly are you stuck?

3. Member
Join Date
Feb 2010
Posts
5
Rep Power
0
Let me to give you an example.
We suppose that we have a number between (11-50)€.so we have to express it using 5€,1€ and 1 cent.

example: 48.5 € = 5 € * 9 + 1 € *3 + 1 cent * 5
Im confused how to separate the input(double) number.

4. Member
Join Date
Feb 2010
Posts
5
Rep Power
0
I've already done but there is only one problem left.How to make cents as int numbers for example we have 0.7 cents to make as 7 cents without decimal point.

Take a look at my work.

Java Code:
```package tester;

import java.text.DecimalFormat;

import javax.swing.JOptionPane;

public class Sum
{

public static void main(String[] args)
{
DecimalFormat formater = new DecimalFormat("0.0");
String s = JOptionPane.showInputDialog("Write a number between 1 and 50 : ");
double inputNum  = Double.parseDouble(s);
if(inputNum<10)
{
double cent = (inputNum%1);
int oneEuro = (int)(inputNum%2);
int twoEuro =(int) inputNum/2;

System.out.println("1 € * "+oneEuro);
System.out.println("2 € * "+ twoEuro);
System.out.println("cents "+formater.format(cent));
}
else if(inputNum>10 && inputNum<50)
{
double cent  = inputNum%1;
int oneEuro = (int) (inputNum%5);
int fiveEuro = (int) inputNum/5;

System.out.println("5 € * "+ fiveEuro);
System.out.println("1 € * "+oneEuro);
System.out.println("Cents: "+formater.format(cent));
}

else
{
}
}

}```
Last edited by xmenus; 02-15-2010 at 03:27 PM.

5. What happens if you multiply cents by 100? If you want to truncate the results, then you could cast the result as an int:

Java Code:
`int centsDisplay = (int) (100 * cent);`

6. Member
Join Date
Feb 2010
Posts
5
Rep Power
0
Thanks man.We just need to multiply by 10.
Java Code:
` int centsDisplay = (int) (10 * cent);`
I appreciate your effort so much.
Thanks again.

7. Senior Member
Join Date
Feb 2010
Location
Ljubljana, Slovenia
Posts
470
Rep Power
8
I do think you should multiply by 100, after all, 0.7€ is 70 cents, not 7.

Thanks man.We just need to multiply by 10.
Java Code:
` int centsDisplay = (int) (10 * cent);`
I appreciate your effort so much.
Thanks again.
You're welcome, but please remind me not to do any financial transactions with you. ;)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•