You have to write a program which takes 30 integers representing collection of coins. Each integer represents worth of each coin. The program should also take another input “amount” whose change needs to be found. Your program should be finding the change using minimum number of coins. If change is not possible then it should display an appropriate message. Output of the program should be list of all coins used to find the change using minimum number of coins. Any number could be input from 0 to infinite...This is only for beginners!

Recommended Answers

All 3 Replies

What have you tried so far? Have you tried out an example with paper and pencil to get the thought process (which makes it much easier to code)?

Also please see this:
http://www.daniweb.com/forums/announcement8-2.html

What have you tried so far? Have you tried out an example with paper and pencil to get the thought process (which makes it much easier to code)?

Also please see this:
http://www.daniweb.com/forums/announcement8-2.html

i did this and now its working!

# include <iostream>
using namespace std;
void main()
{
	int x[10],a=0,amount=0,b,temp,c=0,d=0;


	cout<<"Enter your coins:"<<endl;

	for (a=0;a<=9;a++)		//enter array
		cin>> x[a];
//sorting array so that amount could be compared later on

	for (b=0;b<=9;b++)
	{
		for(a=b+1;a<=9;a++)
		{
			if (x[a]>x[b])
			{
				temp=x[a];
				x[a]=x[b];
				x[b]=temp;
			}
		}
	}
//entering amount

	cout<<"Enter Amount:"<<endl;
	cin>>amount;		//getting the desired number
	cout<<endl<<"Your Change: "<<endl;

	c=amount;

	//comparing each number with amount
	for (a=0;a<=9;a++)
	{
		if ((x[a]==amount))
		{
			cout<<amount<<"...";
			amount=amount-x[a];
			d=x[a]+d;
		}
	}

	amount++;
	for (a=0;a<=9;a++)
	{
		if((x[a]!=amount)&&(x[a]<amount))
		{
			cout<<x[a]<<"...";
			amount=amount-x[a];
			d=x[a]+d;
			
		}

		
	}
//this is used as the default statement if the entered amount is inappropriate

	if (d!=c)
		cout<<endl<<"Please enter your desired amount again as you do not have sufficient coins to get that change...";
	
	cout<<endl;
		
}

As you did disabled communication emails from forum and do not wish to received any PM from other members you leave me no choice then reply publicly.

This thread cannot be removed from the forum because: Acceptable Use Policy - Legal Obligations

DaniWeb LLC reserves full rights and privileges to information posted to anywhere within the daniweb.com domain by its members and staff.

Also when ever you post your assignment on technical forums and need help to solve issue you are cheating on your teacher, and also you are publishing what ever you done. I'm sorry we will not remove it and if you have problem with your classmates possibly copying your work you should mention to your teacher that you posted part of your work on a forum.

Therefore any further request for removal of above posts will be ignored.

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.