1 2 3
|
for(int i = 5; i < 5; i++)
{
}
|
When seeing the output of c, i find that the length of the random letters generated is 7 every single time, which i realized is the difference of the 3 and 10. |
The loop in your never evaluates its body, because 5 is never less than 5.
Your code has no 3, no 7, nor 10 anywhere.
either greater than or equal to 5,
or less than or equal to 7. |
Every number is
(5 <= x) or (x <= 7)
. Lets take 42. It is not less than 7, but it is more than 5. The OR says that that is enough.
Perhaps you mean
(5 <= x) and (x <= 7)
? With AND both subconditions must be true simultaneously. In math you could express that with
5 <= x <= 7
, but C++ requires the
and
.
There is no half a char, so integers. You want length of 5, 6, or 7?
The
for (int i = 0; i < len; i++)
repeats len times.
The
rnd57( rng )
in Duthomas code is similar to a call to rand() that returns 5, 6, or 7.
Thomas code
4 + (rand() % 10)
does ...
the
rand() % 10
returns 0, 1, .. 9. Numbers 0--9.
With the +4 one gets numbers 4--13.
The Duthomas version is recommended, for someone wants to remove the rand() for good.
Nevertheless, you want len to be 5+0 or 5+1 or 5+2, don't you?