Member Avatar for 111100/11000
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <cstring>
using namespace std;
char Outputing(char shifted_letter);
int found_match;
int searching_alphabet;

int main()
{
    const char ORIGINAL_alphabet[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};  //maybe const isn't necesery
    char alphabet[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    cout << "This program encrypts messages using Ceaser Cipher\n";
    cout << "\n---------------------------------------------------------";
    cout << "\n---------------------------------------------------------";
    cout << "\nEnter plaintext or enter ABC to use alphabet as plaintext:\n";
    cin >> alphabet;
    if (stricmp(alphabet,"abc") == 0)   //comperes alphabet and ABC
                {
                cout << "\nAlphabet selected as plaintext\n";
                cout << "\n---------------------------------------------------------";
                cout << "\nEnter shift for alphabet:\n";
                int shift_for_alphabet;
                cin >> shift_for_alphabet;
                cout << "Alphabet set:";
                    for (int i=0;i<26;i++)
                    {
                        alphabet[i] = static_cast<int> (alphabet[i]) + shift_for_alphabet;
                        if((int)alphabet[i]>122)   //if alphabet is shifted more than letter Z
                        {
                        alphabet[i] = (int)alphabet[i]-26;
                        cout << alphabet[i];
                        }
                        else
                        {
                        cout << alphabet[i];
                        }
                    }
                cout << "\n---------------------------------------------------------\n";
                string plaintext;
                cout << "Enter text to shift\n:" <<endl;
                cin >> plaintext;
                    for (searching_alphabet=0;searching_alphabet<26;searching_alphabet++)
                    {
                        if(plaintext == ORIGINAL_alphabet[searching_alphabet])     //error line
                        {
                            Outputing(alphabet[searching_alphabet]);
                            break;
                        }
                    }
                cout << "\n---------------------------------------------------------\n";
                }
    else
                {
                //program not finished...
                }
    system("PAUSE");
    return 0;
}
char Outputing(char shifted_letter)
{
    cout << shifted_letter;
}
    //program not finished...
    //program not finished...
    //program not finished...
    //program not finished...
    //program not finished...

I get error on this line: "if(plaintext == ORIGINAL_alphabet[searching_alphabet])"
**This is error:***error: no match for 'operator==' in 'plaintext == ORIGINAL_alphabet[searching_alphabet]*
I know i need to overload operator "==" but i don't know how

How do you intend to compare a string to a single character? An overloaded operator does not seem valid there. Perhaps create some kind of areEqual function instead. My guess is that you have made a logic error in that you are trying to compare two variables of different types (very different types).

commented: I changed from "string plaintext" to "char plaintext" and it works.Thnx +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.