We can calculate the mass of "C"C from the mass of "CO"_2CO2.
"Mass of C" = 12 color(red)(cancel(color(black)("g CO"_2))) × "12.01 g C"/(44.01 color(red)(cancel(color(black)("g CO"_2)))) = "3.27 g C"
"Mass of H" = "4 g - 3.27 g" = "0.73 g"
Now, we must convert these masses to moles and find their ratios.
From here on, I like to summarize the calculations in a table.
bb("Element"color(white)(X) "Mass/g"color(white)(X) "Moles"color(white)(m) "Ratio"color(white)(m)"×2"color(white)(ml)"×3"color(white)(m)"Integers")
color(white)(ml)"C" color(white)(XXXmm)3.27 color(white)(mml)0.272color(white)(Xm)1color(white)(Xmmll)2color(white)(mml)3color(white)(mmml)3
color(white)(ml)"H" color(white)(XXXmm)0.73 color(white)(mml)0.72 color(white)(mmll)2.64 color(white)(Xm)5.29color(white)(m)7.94color(white)(mm)8
The empirical formula is "C"_3"H"_8.