There is more than one carbon atom in each molecule. So, you need to know the structure in order to calculate the oxidation number in each of these carbons atoms, because the arrangement of atoms is what matters, not the mere number and type of atoms.
To give you more insight into what I'm talking about, the different oxidation numbers of carbons present in ascorbic acid : +3,+1,0,-1 (no particular order)