When using FOR, isn't it START; END; INCREMENT? If so, how can END be less than or equal to something? That isn't a proper end is it? Can't it stop anywhere between 0 and length in this loop?:
for (ctr = 0; ctr <= length; ctr++)
This is for a Caesar cipher I'm making. I'm using IFs inside of the loop. Is this the correct syntax?:
1 2 3 4 5 6 7 8
for (ctr = 0; ctr <= length; ctr++)
{
if (in[ctr]=='a')
{
out[ctr] = 'z';
}
// Rest of IFs...
}
If this isn't correct, please tell me what to fix.
Thanks. Oh and, with calling Funtions, is there a way I can call a function multiple times without having to c&p the call over and over again? I want to have it call "randchar" x times, when x equals a random number. I'm using this for a project where it generates a random number called "x" and calls "randchar" x times. Is this possible?
Okay, checking out a C++ book from the library soon. Now then, I'm using a FOR loop now for the calling of functions. Exactly how do I use if without arrays to read the next char of the input variable like "a", then export a seperate character like "z" to the output variable? I want to do it like this:
1 2 3 4
if (input[ctr] == 'a')
{
output[ctr] = 'z'
}
Then I want to combine all of the seperate output variables using STRING like this:
1 2 3 4 5
for (ctr = ctr; ctr > 0; ctr--)
{
string x = output[ctr];
string result = result + x;
}
The problem being is that I don't know how to name a variable after a variable. I want it to be like this:
output4 = x
Where "x" equals the outputted CipherChar, and output is the variable name, and "4" equals "ctr". But I want both variables to combine and equal x.
How does the array apply to the variable? (I lost the original page and can't seem to locate it.) Does it make the variable value become the array? Idk what's going on with the IFs yet. And exactly how do I read a variable, char by char, with IF? I have c set as the current char to read, but I don't know how to skip to the next char of the input variable:
1 2 3 4 5
string o;
if (c = 'a')
{
o = o + Z
}
Do I need to replace o = o + 'z'; with string o = o + 'z'; to add 'Z' to o, the output? Should I maybe split the input into a char array then have BitCrypt read the array char by char?