A spy was wiretapping an enemy's headquarters' entrance. He found out that before one can enter, he must reply to a code.
A man entered the building. the guard said 12. The man answered 6. He was allowed inside.
Another man entered the building. the guard said 6. the man answered 3. He was also allowed inside.
Feeling he heard enough, the spy tried to enter the building. The guard said 18. He answered 9. The spy was arrested.
What should the spy have answered and why?