i need some help with a Question i have been giving in a Revision Practical, tell me where i am going wrong PLEASE. Go easy on me i have only started learning java 5 weeks now im doing a B.Sc. (Hons) in Applied Computing.
The question is: Write a program that will accept a monetary amount in euro as input and will compute and display the number of each coin needed to make up this amount using the least number of coins possible. Only the following coins can be used 2 euro, 1 euro, 50 cent, 20 cent, 10 cent, 5 cent, 2 cent and 1 cent.
Sample output:
€2.99 is made up of
1 x 2euro + 0 x 1euro + 1 x 50 cent + 2 x 20 cent + 0 x 10 cent + 1 x 5 cent + 2 x 2 cent + 0 x 1 cent
here is what i have done so far and i cant get it to go beyond 1 euro...
// Gman
// 26/10/2011
// euro to coin's program
import java.util.Scanner;
public class EuroToCoinSolve
{
public static void main(String[] args)
{
//create instance of scanner
Scanner kb = new Scanner(System.in);
// declare variable
int twoEuro, oneEuro, twoEuroR, oneEuroR, amountN;
int fiftyCent, twentyCent, tenCent;
int fiftyCentR, twentyCentR, tenCentR;
double amount, fiveCent, twoCent, oneCent, fiveCentR, twoCentR, oneCentR;
//get user input
System.out.print("Enter euro to change in euro coins: ");
amount = kb.nextDouble();
amountN = (int)amount * 100;
twoEuro = amountN / 200;
twoEuroR = amountN % 200;
oneEuro = twoEuroR / 100;
oneEuroR = twoEuroR % 100;
fiftyCent = oneEuroR / 50;
fiftyCentR = oneEuroR % 50;
twentyCent = fiftyCentR / 20;
twentyCentR = fiftyCentR % 20;
tenCent = twentyCentR / 10;
tenCentR = twentyCentR % 10;
fiveCent = tenCentR / 5;
fiveCentR = tenCentR % 5;
twoCent = fiveCentR / 2;
twoCentR = fiveCentR % 2;
oneCent = twoCentR / 1;
System.out.println(amount + " is made up of \n" + twoEuro + " x 2Euro " + oneEuro + " x 1Euro "+ fiftyCent + " x 50 Cent " + twentyCent + " x 20 Cent " + tenCent + " x 10 Cent " + fiveCent + " x 5 Cent " + twoCent + " x 2 Cent " + oneCent + " x 1 Cent " );
}
}


Sign In
Create Account


Back to top









