Lets say I am given a certain mass of a compound. Additionally, the number of moles of the compound itself are known, as well as its molar mass. How can I, using an equation, find the number of atoms (in moles) of an element in said compound?
After trying myself, I derived the equation, $A = \frac{pm}{a}$, where $A$ is the number of atoms, $p$ is the percent composition, $m$ is the mass of the compound, an $a$ is the AMU measure of the element. Logically, it seems this would work. However, it does not algebraically. This is because $p = \frac{a}{M}$, where $M$ is the AMU measure of the compound. If you factor that in, you can see that both $a$'s cancel each other out, so I end up with the same answer for any element of the same compound.
What can I do to prevent this from happening?
If $m$ is the mass of the compound in grams, and $M$ is the AMU mass of the compound, there are $N_A \frac mM$ molecules of the compound, where $N_A$ is Avogadro's number. The mass of your atoms is then $mp$ and the number of atoms is $A=N_A\frac {mp}a$