encryption function help

I can't figure out whats going on with my code.

This function is taking text from an input file, encrypting it, and outputting it into a file. In my for loop, it is doing the first part but not the second part(meaning if the input letter is greater than z)
can I get a little help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
void EncryptRot(vector<string>Original,int key)
{
  vector<string>EncryptedFile;
  int tempLet;

  //makes sure lowercase letters are within boundries                                                                                                                  
  for( int a = 0; a < Original.size(); a++)
    {
      for (int b = 0; b < Original[a].size(); b++)
        {
          if (Original[a][b] >= 'a' && Original[a][b] <= 'z')
              tempLet = Original[a][b] + key;

              if (tempLet > 'z')
                {
                  Original[a][b] = tempLet - 26;
                }
              if (Original[a][b] >= 'a' && Original[a][b] <= 'z')
                {
                  Original[a][b] = tempLet;
                }
            }
          //makes sure uppercase letters are within boundries                                                                                                          
          if(Original[a][b] >= 'A' && Original[a][b] <= 'Z')
            {
              tempLet = Original[a][b] + key;
              {

              if (tempLet > 'Z')
                {
                  Original[a][b] = tempLet - 26;
                }
              if (Original[a][b] >= 'A' && Original[a][b] <= 'Z')
                {
                  Original[a][b] = tempLet;
                }

 }
        }
        }
      EncryptedFile.push_back(Original[a]);
    }
  ofstream fou;
  fou.open("encrypt01.txt");



  for (int a = 0; a < EncryptedFile.size(); a++)
    {
    fou << EncryptedFile[a];
    fou << " ";
    }
  fou.close();
}
Last edited on
Please edit your post as bracket your code with code tags (the <> formatting button).

I see several things wrong, but can't post a meaningful reply without line numbers to refer to.
ah, I'm such a noob!
Thanks for editing your post to add code tags.

What I see is:
Line 24: variable b has gone out of scope. b is defined only within the for loop at line 9. It goes out of scope with the } at line 22.
Line 26, 31,33,35: ditto

Did you intend the } at line 22? Your indentation and code seem to imply otherwise.
If I remove the } at line 22, your code compiles cleanly.

edit: Or perhaps you're missing an { at line 12. If I compare the two for loops, I see an { at line 25.
Last edited on
Topic archived. No new replies allowed.