Member Avatar for 111100/11000
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <cstring>
using namespace std;

int main()
{
    char chouseing_alphabet[27]={'a', 'b', 'c', '\0'};
    string abc[27];
    cout << "This program encrypts messages using Ceaser Cipher\n";
    cout << "NOTE:capital letters are not allowed in this program\n";
    cout << "\n---------------------------------------------------------";
    cout << "\n---------------------------------------------------------";
    cout << "\nEnter plaintext or enter abc to use alphabet as plaintext:\n";
    cin >> abc[27];
    cout << "\n---------------------------------------------------------";
    if ((&chouseing_alphabet[0] == abc[0])||(&chouseing_alphabet[1] == abc[1])||(&chouseing_alphabet[2] == abc[2]))
                {
                //custom_alphabet[27]=abc[27];
                cout << "\nCustom alphabeth selected as plaintext\n";
                //custom_alphabet[27]++;
                //cout << custom_alphabet[0]++;
                }
    else
                {
                cout << "\nAlphabet selected as plaintext\n";
                //char alphabet[27]={'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','\0'};
                //alphabet[27]++;
                //cout << alphabet[0]++;
                }

    system("PAUSE");
    return 0;
}   //program not finished...
    //program not finished...
    //program not finished...
    //program not finished...
    //program not finished...
    //program not finished...
Member Avatar for 111100/11000

IT ALWAYS COUTS "Alphabet selected as plaintext"

try to use strcpy in assigning a value to chouseing_alphabet and strcmp in comparing the 2 string

huuhaa

Quick question, what text do you have to decipher?

if ((&chouseing_alphabet[0] == abc[0])

Why are you trying to compare the address of a variable with the value of another variable? abc[0] is not an address. If you only want to compare the two characters then remove the & address operator.

Member Avatar for 111100/11000

If i remove "&" address operator than i get error:

-------------- Build: Debug in Caesar Cipher ---------------

Compiling: main.cpp
C:\Dev-Cpp\PROJECTS\Encryption machines\Caesar Cipher\Caesar Cipher\main.cpp: In function `int main()':
C:\Dev-Cpp\PROJECTS\Encryption machines\Caesar Cipher\Caesar Cipher\main.cpp:19: error: no match for 'operator==' in 'chouseing_alphabet[0] == abc[0]'
C:\Dev-Cpp\PROJECTS\Encryption machines\Caesar Cipher\Caesar Cipher\main.cpp:19: error: no match for 'operator==' in 'chouseing_alphabet[1] == abc[1]'
C:\Dev-Cpp\PROJECTS\Encryption machines\Caesar Cipher\Caesar Cipher\main.cpp:19: error: no match for 'operator==' in 'chouseing_alphabet[2] == abc[2]'
Process terminated with status 1 (0 minutes, 0 seconds)
3 errors, 0 warnings

111100/11000: strcpy doesn't compare but compys from one string to another

you missed reading a word in my previous comment

... and strcmp in comparing the 2 string

commented: Thanks +0
Member Avatar for 111100/11000

I've solved it thanks to zeroliken
this is solution:

#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <cstring>
using namespace std;

int main()
{
    char abc[27];
    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 >> abc;
    cout << "\n---------------------------------------------------------";
    if (stricmp(abc,"abc") == 0)    //simple and elegant
                {
                cout << "\nAlphabet selected as plaintext\n";
                }
    else
                {
                cout << "\nCustom alphabeth selected as plaintext\n";
                }

    system("PAUSE");
    return 0;
}   //program not finished...
    //program not finished...
    //program not finished...
    //program not finished...
    //program not finished...
    //program not finished...

If this is a school assignment you might not want to use stricmp() because its non-standard and may or may not be supported by your instructor's compiler.

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.