I have to write a program that finds the center of gravity.

Begin by writing, on paper, what you want your program to do. What do you want the input to be, what do you want the output to be, what is legal data, what is illegal data? Decide whether you need to design a class or a struct, and if so, what should be in there. Design some function prototypes. Then design the functions that go along with these prototypes that do nothing but return the correct data type. Start with your simplest program:

int main ()
     return 0;

Compile it, run it, make sure there are no errors, add one small piece at a time, stop, see what errors you get, look at the top error, fix that, recompile and run. Don't get too detailed at first. Start with a skeleton, make sure everything works within that skeleton, then add details.