Carbon weight=12 grams
Hydrogen weight=1 gram
Oxygen weight=16 grams
C to H ratio (mass)=6
Therefore for each carbon, you have two units of hydrogen
So far it is
C to O ratio is
Since for 1 Carbon (12 grams), you need some oxygen:
where C=12 grams (for one mole)
Exactly Oxygen has a weight of 16 grams per mole.
Therefore your formula for this case is;
where you have a molecular weight of 30 grams per mole.
Your formula is