The key is to think about how you did the maths yourself.
I expect your internal algorithm ran something like this:
Is amount of silver bigger than 1000?
If no, then it's just silver. Not gold.
If yes, then there is a gold value.
How many thousands of silver are there?
There is ONE thousand, with none left over.
So I have ONE gold, and NO silver.
Then just take each piece and write the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Is amount of silver bigger than 1000?
if (silver>1000)
{
// If yes, then there is a gold value.
// How many thousands of silver are there?
int numberOfThousandsOfSilver = silver/1000;
gold = numberOfThousandsOfSilver;
// How much silver left over?
silver = silver - (numberOfThousandsOfSilver * 1000);
}
else
{
// If no, then it's just silver. Not gold.
}
cout <<"You have gold " <<gold <<" and silver " <<silver <<endl;
}