Caesar Cipher reading...

I get the error of not declaring but I how do I declared those variables,
even if they cause problem to file...
how can I output the decipher file in a new text...?

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
  #include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;

int main()

{

    // Declarations

    string reply;

    string inputFileName;

    ifstream inputFile;

    char character;



    cout << "Input file name: ";

    getline(cin, inputFileName);



    // Open the input file.

    inputFile.open(inputFileName.c_str());     
    // Check the file opened successfully.

    if ( ! inputFile.is_open()) {

        cout << "Unable to open input file." << endl;

        cout << "Press enter to continue...";

        getline(cin, reply);

        exit(0);


    }

    // This section reads and echo's the file one character (byte) at a time.

    while (inputFile.peek() != EOF) {

        inputFile.get(character);

        cout << character;

    char cipher[sizeof(character)];



    int shift;
    do {
        cout << "enter a value between 1-26 to encrypt the text: ";
        cin >> shift;
       } 
    while ((shift <1) || (shift >26));

    int size = strlen(text);
    int i=0;

    for(i=0; i<size; i++)
    {
        cipher[i] = text[i];
        if (islower(cipher[i])) {
            cipher[i] = (cipher[i]-'a'+shift)%26+'a';
        }
        else if (isupper(cipher[i])) {
            cipher[i] = (cipher[i]-'A'+shift)%26+'A';
        }
    }

    cipher[size] = '\0';
    cout << cipher << endl;



    }

    cout << "\nEnd of file reached\n" << endl;

    // Close the input file stream

    inputFile.close();

    cout << "Press enter to continue...";

    getline(cin, reply);

    return 0;   

}

Topic archived. No new replies allowed.