Given the coin denominations 1, 3, and 5, what is the minimum number of coins needed to
make change for a given value?
Hint:
Value 1 2 3 4 5 6 7 8 9 10
Min.
no.
Coins 1 2 1 2 1 2 3 2 3 2
Parameter to be used : the amount of Money M and
the array of denominations C.

I have to use this relation:
minNumCoins(M-1) + 1
minNumC oins(M-3) + 1
minNumCoins(M-5) + 1

Underlining all the red words and giving me this error: The method minNoCoins(int m,int []C) in the type coins is not applicable for the arguments int.Please help me with this program

import java.util.Scanner;

public class coins {
	
	public static int minNoCoins(int m,int []C)  
	{
		for (int i=0;i<3;i++)
		if (m>=5) 
		{
			return minNoCoins(m-C[2])+1;  
		}
		else if (m>=3) 
		{
			return minNoCoins(m-C[1])+1;
		}
		else if (m==1) 
		{
			return minNoCoins(m-C[0])+1;
		}
		else return 0;
	}
	
	
	
	public static void main(String[] args) {
		
		Scanner input= new Scanner(System.in);
		int C[]={1,3,5};
		
		
		
		System.out.println ("Enter amount of Money:");	
		int m=input.nextInt();
		
	
		
		for (int i=0;i<3;i++)
			System.out.println("Min number of coins: "+minNoCoins(m,C[i]));
		}
	
}

You declared function as

public static int minNoCoins(int m,int []C)

but you are calling it as

minNoCoins(m-C[2])+1;

You are passing in only an "int" variable but no "int[]" array.

tell me how to pass the other parameters please?help me

You need to keep passing C into the call.

return minNoCoins(m-C[2], C)+1;

PS: You need to try to understand how you call a method. It is crucial for you in the future.

Yes. i was a bit confused with this one.
now i need to output the number of miminum coins and the coins that have been used.
for example m=6:
minimum coins=2 , coins used= coin 1 n coin 5

How will i do this?

Member Avatar for hfx642

You are also trying to use your method as a variable, within itself.
For what you are trying to achieve, this won't work.

As hfx642 said, the way you are doing now is to "count" only, but not to "keep track" of which is counted. You need to come up with a way to keep track. Passing another variable to keep track is one way to do. *hint hint*

hmmm...still confused.help me please

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.