Ive just started working with Java at Uni and im doing a little project including
floating, double, and integer numbers.

Ive simplified the project just so you can see what the basics are.

  • The bottom 3 print lines show how many of a single type of coin are required to make the specified value
  • The top 3 print lines are ment to show how many differnet coins are required to make the specified value

But basically the top 3 are only showing the pound coins and not the other values.
I kinda know whats wrong but I dont know how to resolve it.

Heres the results if you dont want to run the code:
One Pounds: 2
Fifty Pences: 0
Twenty Pences: 0

One Pounds: 2
Fifty Pences: 5
Twenty Pences: 13

Thanks

class bt
{
	public static void main ( String args [ ] )
	{
		
		//declare and initialise variables
		float sterling = 2.7f;
		String indent = "     " ;
		int ones, fifties, twenties;
		int one, fifty, twenty;
		double money;
		money = sterling;
		double moneies;
		moneies = sterling;
		
		ones = (int) (money / 1);	
		money = ones % 1;	
		fifties = (int) (money / 0.5);
		money = money % 0.5;
		twenties = (int) (money / 0.2);
		
		one =  (int) (moneies / 1);	
		fifty = (int) (moneies / 0.5);
		twenty = (int) (moneies / 0.2);
		
		System.out.println( indent + "One Pounds: " + ones) ;
		System.out.println( indent + "Fifty Pences: " + fifties) ;
		System.out.println( indent + "Twenty Pences: " + twenties) ;
		System.out.println("");
		System.out.println( indent + "One Pounds: " + one) ;
		System.out.println( indent + "Fifty Pences: " + fifty) ;
		System.out.println( indent + "Twenty Pences: " + twenty) ;
		
		
	}
}

Solved.

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.