0

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.

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by sfuo
0

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;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.