Charle's Law:
$\frac{V}{T}=k$
The idea is that, given an ideal gas, as the temperature rises the system instantly responds by balancing the potential increase in pressure with an actual increase in volume.
In the case of the piston, you can easily measure the work done by measuring how much the piston moved. But in a general case:
$dW = Fdx$
$Fdx$ or force times movement interval could be written as pressure (force over area) times interval of area times area interval times movement interval or $dW = pdAdx$. You can represent that better with $dW = pdV$ or volume interval.
So for a general case, with constant pressure, the work done by the gas is $W = p(V_f - V_i)$.
Nevertheless, depending on what they ask, you might need to use:
$pV = nRT$
In that case, you need to solve the integral:
$W = nRT\int_{V_i}^{V_f} \frac{dV}{V}$
Which solves to:
$W=nRT(\ln{V_f} - \ln{V_i})$
Or
$W=nRT \ln{\frac{V_f}{V_i}}$
The derivation of ideal gas equation from Hamilton's equations will take the same procedure as what you have seen in Wikipedia. Since you said you haven't understood the way in which the equation is derived I will give you a step by step explanation on it.
So we have a system of perfect gas molecules. Of course they are non-interacting. We are going to deal their motion using Hamiltonian mechanics. So we consider our system in phase space. Let $\textbf{q}=(q_x,q_y,q_z)$ and $\textbf{p}=(p_x,p_y,p_z)$ represent the position and momentum vectors of a particle in the system. Here $q_x$, $q_y$, $q_z$ represent the position coordinates along the three axes and $p_x$, $p_y$, $p_z$ represent the corresponding momentum coordinates. Let a force $\textbf{F}$ acts on the system. Then the potential energy of the particle is given by the work done by this force to displace the particle from , say, origin to the position q.
$$\textbf{q}\cdot\textbf{F}=q_x\frac{dp_x}{dt}+q_y\frac{dp_y}{dt}+q_z\frac{dp_z}{dt} \longrightarrow(1)$$
where the right hand side is given by Newton's second law.
The time average of this potential energy is given by:
$$\langle\textbf{q}\cdot\textbf{F}\rangle=\langle q_x\frac{dp_x}{dt}\rangle+\langle q_y\frac{dp_y}{dt}\rangle+\langle q_z\frac{dp_z}{dt}\rangle \longrightarrow(2)$$
We have from hamilton's equation of motion that
$$\dot{p}=\frac{dp}{dt}=-\frac{\partial{H}}{\partial{q}} \longrightarrow(3)$$
So we write equation (2) as
$$\langle\textbf{q}\cdot\textbf{F}\rangle=-(\langle q_x\frac{\partial{H}}{\partial{q_x}}\rangle+\langle q_y\frac{\partial{H}}{\partial{q_y}}\rangle+\langle q_z\frac{\partial{H}}{\partial{q_z}}\rangle) \longrightarrow(4)$$
Now we are going to invoke the equipartition theorem. According to the equipartition theorem the total kinetic energy of a system is shared equally among all of its independent parts, on the average, once the system has reached thermal equilibrium. Also it predicts that every atom of an ideal gas, in thermal equilibrium at temperature $T$, has an average translational kinetic energy of $\frac{3}{2}k_BT$ where where $k_B$ is the Boltzmann constant. Of these the contribution along each degree of freedom is $\frac{1}{2}k_BT$.
So we have got the kinetic energy of each particle using equipartition theorem. Since we are considering a system of non-interacting particles, we can invoke Virial theorem. By this theorem the potential energy of the system of particles will be twice as the kinetic energy of the particles in the system. This is valid for a single particle in the system also since the energy of all particles are the same at a given temperature. Hence equation (4) becomes
$$\langle\textbf{q}\cdot\textbf{F}\rangle=-(\langle q_x\frac{\partial{H}}{\partial{q_x}}\rangle+\langle q_y\frac{\partial{H}}{\partial{q_y}}\rangle+\langle q_z\frac{\partial{H}}{\partial{q_z}}\rangle)=-3k_BT \longrightarrow(5)$$
Suppose there are $N$ particles in the system. then the total potential energy of the system is given by
$$-\sum_{k=1}^N\langle\textbf{q}\cdot\textbf{F}\rangle= 3Nk_BT \longrightarrow(6)$$
Now, by Newton's third law the force exerted on the particle is equal and opposite to the force exerted by particles on the container walls. This is the pressure of the gas $P$. Since the force acting on each particle is the same, the pressure of the gas at any point is the same. So if we have an elemental surface $d\textbf{S}$ of the container, then the force is given by
$$-\textbf{F}=P\oint_{surface} d\textbf{S}$$
where the negative sign implies it's the reaction force of particles on the container surface that causes pressure. Hence equation (6) becomes
$$-\sum_{k=1}^N\langle\textbf{q}\cdot\textbf{F}\rangle=P\oint_{surface} \textbf{q}\cdot d\textbf{S} \longrightarrow(7)$$
Now, we are going to invoke the Gauss's divergence theorem. According to it
$$\oint_{surface} \textbf{q}\cdot d\textbf{S}=\int_{volume} (\nabla\cdot \textbf{q}) dV$$
where the right hand side implies the volume integral of the divergence of $\textbf{q}$ from an elemental volume. So equation (7) can be rewritten as
$$-\sum_{k=1}^N\langle\textbf{q}\cdot\textbf{F}\rangle=P\int_{volume} (\nabla\cdot \textbf{q}) dV \longrightarrow(8)$$
Now, let's find the divergence of $\textbf{q}$.
$$\nabla\cdot \textbf{q}=\frac{\partial{q_x}}{\partial{q_x}}+ \frac{\partial{q_y}}{\partial{q_y}}+\frac{\partial{q_y}}{\partial{q_y}}=3$$
Hence we write
$$-\sum_{k=1}^N\langle\textbf{q}\cdot\textbf{F}\rangle=3P\int_{volume} dV=3PV \longrightarrow(9)$$
where V is the volume of the gas. Now from equation (6), (9) becomes
$$3PV=3Nk_BT$$ or
$$PV=Nk_BT \longrightarrow(10)$$
Now we are going to do some manipulations. Equation (10) is not that useful in practical case as it requires the total number of gas molecules. But we know that 1 mole of gas contains Avogadro number ($N_A$) of molecules. So $n$ mole of gas contains $N=nN_A$ number of molecules. So we have defined our $N$ number of molecules in terms of $n$ moles. Also, $N_A$ is related to the gas constant $R$ by $R=N_Ak_B$. So finally we get the number of molecules of gas as $N=nR/k_B$. Hence our final equation becomes
$${\color{red} {PV=nRT}}$$
which is the ideal gas equation. Thus our goal is completed.
Hope this helps.
Best Answer
You have to realize first that Charles' law is the change in volume with respect to temperature for constant pressure while Boyle's law is the change in volume with respect to pressure for constant temperature. So when you combine them, you need to account for these
If I take a gas of volume $V_1$, pressure $P_1$ and temperature $T_1$ and let it change have a state $(V_*,\,P_2,\,T_1)$, then via Boyle's law, $$ P_1V_1=P_2V_*\tag{1} $$ Then keeping this constant pressure we move to state $(V_2,\,P_2,\,T_2)$ via Charles' law, $$ \frac{V_*}{T_1}=\frac{V_2}{T_2}\tag{2} $$ Solving for $V_*$ in both (1) and (2) then equating them, we get $$ \frac{P_1V_1}{T_1}=\frac{P_2V_2}{T_2} $$ We've changed the pressure, volume and temperature of the gas but still find their product equal, suggesting that the relation is constant: $$ \frac{PV}{T}=k $$