The total charge of the carbonate ion is -2. O2 in CO32- has a total charge of -6 (3 x -2). Hence, to find the charge of carbon -> x + -6 = -2. Therefore, carbon has a charge of +4.
This matches your theory stated whereby
1. Carbon has 4 valence electrons so in this case, it loses 4 electrons to obtain a stable noble octet config. & hence has a charge of +4.
2. Oxygen has 6 valence electrons so in this case, it gains 2 electrons & hence has a charge of -2.