I have a homework. i don't understand it. Can you help me

Given an amount of money (less than 10,000VND), compute the number coin of 500VND, 1,000VND, 2,000VND, 5,000VND needed. Remember that the number of coin is minimized.

Thanks.

I have a homework. i don't understand it. Can you help me

Sure.

This seems like a pretty bad homework assignment seeing how you can only use a few coins to get 10000 dongs.

This is what I put together really quick. It's not done you need to come up with an output and you might wanna double check to see if the input limits are right.

int main()
{
	int input;
	
	int values[4] = {5000,2000,1000,500};
	
	int amounts[4] = {0,0,0,0};
		
	cout << "How many dongs?" << endl;
	cin >> input;
	
	if( input > 10000 || input < 0 || input % 500 != 0 )
	{
		return 1;
	}
		
	for( int i = 0; i < 4; i++ )
	{
		if( input >= values[i] )
		{
			amounts[i] = input / values[i];
			input -= values[i] * amounts[i];
		}
		
		if( input == 0 )
		{
			break;
		}
	}
	system("PAUSE");
	return 0;
}
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.