When do we use the formula $E=kQ/r^2$? 
A cube of side 20 cm has its center at the origin and its one side is along the x-axis, so that one end is at x = +10cm and the other is at x = -10cm. The magnitude of electric field is 100 N/C and for x> 0 it is pointing in the +ve x-direction and for x<0 it is pointing in the -ve x-direction as shown. The sign and value of charges inside the box, are


The actual solution of this question is to be solved using Gauss' Law. However, I solved for charge inside (Q) using the formula E=kQ/r^2, putting E=+100 N/C and r=+0.1 m but the value doesn't match. Can someone guide me as to why my approach is wrong? Why can't we use the formula E=kQ/r^2?
 A: The formula $$E=\frac{kQ}{r^2}$$ should be used for point charges or objects with spherical symmetry and uniform charge distribution.
Using it for arbitrarily shaped uniform (or non-uniform) charge distributions will not allways give the right answer since the question as to what value you would use for $r$ will not be clearly defined. And I think that is why you are getting an incorrect answer.
Using Gauss's law, which actually relates the distribution of electric charge to the resulting electric field, you do an integral over the surface containing the charge distribution, $$\int_S \vec E \cdot \vec {dS} = \frac{Q}{\epsilon_0}$$ which will give you the correct result as you pointed out. In fact, Gauss's law will give you Coulomb's law (which is essentially what you had used originally) if the surface $S$ is a uniformly charged sphere (or a point charge which is still spherically symmetric if you consider the direction/strength of the lines of force which emanate from the charge, at constant values of $r$).
A: The formula $E=\frac{k Q}{r^2}$ is the electric field of a point charge in radial direction at a distance $r$ from the charge. This means, especially, that the field is not homogeneous, i.e. not the same at every point in space. Compare this to your "the magnitude of the electric field is" and you'll find that we are either missing information or the point charge is not the right way to go. Is the field magnitude you mentioned measured on the face of the block and is it homogeneous over it?
As joseph h already suggested, Gauß's law would be a good starting point.
