In order to answer this one we will assume that we have 100 grams of this compound, this will facilitate our resolution and understanding
If we have 100 grams of the compound, 15.8% of Carbon will be equal to 15.8 grams of Carbon, the same is true for Sulfur, 84.2% = 84.2 grams of Sulfur, now we have the mass of each element present in the compound, we have to find out how many moles of each element is present now
We will do that by using their molar mass
Carbon = 12 g/mol
Sulfur = 32 g/mol
Through this we will be able to find how many moles there are in the compound
For carbon we have 15.8 grams
12 grams = 1 mol
15.8 grams = x moles
x = 1.32 moles of Carbon
For sulfur we have 84.2 grams
If we have 32 grams of Sulfur, we will have always 1 mol of Sulfur, this is why it is called molar mass, is the mass that equals to 1 mol of the element, but I want to know how many moles I have in 84.2 grams, so I will call it x moles, because I still don't know
If 32 grams = 1 mol
Then 84.2 grams = x moles
I will multiply the values in a crossing way
32 * x = 84.2 * 1
32x = 84.2
x = 84.2/32
x = 2.63
Now we have the number of moles for each element, 1.32 Carbon and 2.63 Sulfur, but in questions like these we will try our best to make the number the closest possible to an integer number, so let's multiply these two values by 2
1.32 * 2 = 3.96 moles
2.63 * 2 = 7.9 moles
Now it is better for us to identify the formula of the compound, what we need to do now is to divide both values for the lowest one and we will have our empirical formula
3.96/3.96 = 1
7.9/3.96 = roughly 2
Now we have 1 Carbon and 2 Sulfurs in the formula, which is CS2, Carbon disulfide