It has a bit of pseudo code so i'll try to explain
x = 0
for i from 1 to n:
if random() > 1/4:
x = x + 5
else:
x = x - 1
the probability of random() returning a number larger than $\frac{1}{4}$ is $75\%$ and less than $\frac{1}{4}$ is $25\%$
what is the expected value of the final $x$?
attempt:
since x can either be the number of times random() $> \frac{1}{4}$ multiplied by $5$ or the number of times random() $< \frac{1}{4}- 1$, I've reduced the random variable $C$ is the number of times random returns a number greater than $\frac{1}{4}$ and the random variable $D$ as the number of times random returns a number smaller than $\frac{1}{4}$.
So $$E(X) = 5C -1D$$
Since I must preform this operation $n$ times:
$$E(X) = \sum_{i = 1} ^{n} = (5(.75) - 1(.25)) * n$$
$$E(X) = \frac{7}{2} \frac{(n(n+1))}{2}$$
Have I made a mistake in this?
At each iteration, the expected value of $x$ changes by $$5\cdot 0.75 - 1\cdot 0.25 = \frac{7}{2},$$ so the expected value after $n$ iterations is $\frac{7}{2}n$.