-7

This is my code, and for some reason it claims that there are undeclared identifier although I did declare everything

#include <iostream>
#include <string>
#include <fstream>
#include <iterator>
#include <algorithm>

using namespace std;

char a;
char caesarCipher (char );
char caesarDecipher (char );
string input;
string line;
std::string str;

void displayMenu() { 
    cout<<"This program will encrpt/decrypt files";
    cout<<"To encrypt press 'e'/To decrypt press 'd'";
    cin>>a;
}

void encrypt() { 
    string filename,ofilename;          
    cout << "Input filename: ";
    cin >> filename;
    cout << "Output filename: ";
    cin >> ofilename;

    ifstream infile(filename);
    ofstream outfile(ofilename);
    if ((infile >> noskipws) && outfile) {
        std::transform(istream_iterator<char>(infile),
                       istream_iterator<char>(),
                       ostream_iterator<char>(outfile),
                       ceaserCipher);

        string output = "";
        for(int x = 0; x < input.length(); x++) {
            output += ceaserCipher(input[x]);
        }
    }
}

/**************************************************************
* This function decrypts the content of infile and saves the *
* decrypted text into outfile *
* @param infile string (file that has encrypted text) *
* @param outfile string (file that will have decrypted text) *
**************************************************************/
void decrypt() { 
    string filename,ofilename;          
    cout << "Input filename: ";
    cin >> filename;
    cout << "Output filename: ";
    cin >> ofilename;

    ifstream infile(filename);
    ofstream outfile(ofilename);
    if ((infile >> noskipws) && outfile) {
        std::transform(istream_iterator<char>(infile),
                       istream_iterator<char>(),
                       ostream_iterator<char>(outfile),
                       ceaserDecipher);

        string output = "";
        for(int x = 0; x < input.length(); x++) {
            output += ceaserDecipher(input[x]);
        }
    }
}

/**************************************************************
* This function takes an character and a cipher key to return*
* an encrypted character. *
* @param c is a char (the character to be encrypted) *
* @param key is an integer (cipher key given in the handout) *
**************************************************************/
char ceaserCipher(char c) {
    if (isalpha (c)) {
        c = toupper(c);
        c = (((c-65)+5) % 26) + 65;
    }
    return c;
}

char ceaserDecipher(char c) {

    if (isalpha (c)) {
        c = toupper(c);
        c = (((c-65)-5) % 26) + 65;
    }
    return c;
}

int main() {
    char b;

    displayMenu();
    if (a=='e'||a=='E') {
        encrypt;
    }
    else (a=='d'||a=='D'); { 
        decrypt;
    }

    cout<<"To exit input 'e'/To continue press 'c'";
    cin>>b;
    switch (b) {
    case 'c':
        return main();

    case 'e':
        return 0;
        break;
    }
}

These are the errors:

ceaserCipher' : undeclared identifier
ceaserCipher': identifier not found
ceaserDecipher' : undeclared identifier
ceaserDecipher': identifier not found

Any and all help is appreciated

joce
  • 9,624
  • 19
  • 56
  • 74

2 Answers2

3

You have misspelled the function name. You have

char caesarDecipher (char );

while you're trying to use (and later - define) ceaserDecipher (note the different ways of spelling: "ceasEr" and "ceasAr").

Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187
  • I fixed that but the error are still there – john smith Apr 03 '13 at 14:57
  • @johnsmith - not possible. There's no `ceaserDecipher` (described in the error message) in your code at all. Use `ctrl+f` to check it by yourself. The error message is now different or the changed code in your question is not the real one. – Kiril Kirov Apr 03 '13 at 14:59
2

Your forward declarations spell it as caesar, but your function definitions spell it ceasar.

Telgin
  • 1,614
  • 10
  • 10