#include <iostream>
#include <string.h>
#include <ctype.h>

using namespace std;

void RemoveSpaces (char *str);
void Removevowels (char *str);

int main()
{
system("Color 1A");
	
    char myString[300];
    char clear[300];
    char cipher[300];
    int selection;
    int x = 0;
    int i = 0;
    int opt;
    
    cout<<"Enter a string!"<<endl;
    cin.ignore();
    cin.getline(myString,sizeof(myString));
    cout<<"Plase select what you want to do:"<<endl;
    cout<<"\t1) Encrypt"<<endl;
    cout<<"\t2) Decrypt"<<endl;
    cout<<"\t3) Decrypt"<<endl;
    cout<<"\t4) Decrypt"<<endl;
    cin>>selection;
    
    if (selection==1)
    Encrypt(myString);
    cout<<"Your string is now:"<<myString<<endl;
    
    else (selection==2)
    Encrypt and remove space(myString);
    cout<<"Your string is now:"<<myString<<endl;
       
       
    else (selection==3)
    Encryptand remove space and vawels(myString);
    cout<<"Your string is now:"<<myString<<endl;
    
    
     else (selection==4)
    Decrypt your password(myString);
    cout<<"Your string is now:"<<myString<<endl;    
    
    return 0;
    }   
       
        x = strlen(clear);
          // Encryption
              for(i=0; i<=x-1; i++)
                {
                if (isspace(clear[i]))
                {
                cipher[i] = clear[i];
                }
                else
                {
                cipher[i] = clear[i]+3;
                }
                }
                
          // Decryption
                for(i=0; i<=x-1; i++)
                {
                if (isspace(cipher[i]))
                {
                clear[i] = cipher[i];
                }
                else
                {
                clear[i] = cipher[i]-3;
          }
              cout<<cipher[i]<<endl;
              RemoveVowels(clear);
               
          cin.get();
          return 0;
          }
            
              void RemoveSpaces(char *str)//char * is basically the same as char[]
                {
                for (int i=0; str[i]; ++i)//loop until we hit the null character (str[i]==0)
                {
                if (str[i]==' ')//its a space!
                str[i]=' '+3;//or whatever you set it to
                }
            }

              void RemoveVowels(char clear[],char cipher[],int x,int i)
                {
                for(i=0;i<=x-1;i++)
                {
                 
                if (cipher[i]=='a' || cipher[i]=='e' || cipher[i]=='i' || cipher[i]=='o' || cipher[i]=='u' || cipher[i]=='A' || cipher[i]=='E' || cipher[i]=='I' || cipher[i]=='O' || cipher[i]=='U') {
                cipher[i]=' ';
                }
                cout<<cipher[i];
                }
            }
             
            
       cout<<" Encrypted:" << cipher << endl;
       cout<<" Decrypted:" << clear << endl;

    system("pause");
    return 0;
}

dont know what is going on with this code to many error comes out
help...

Really and we're just supposed to know what this does.

  • This is C++ code, not C code.

  • system requires #include <stdlib.h>
  • You have not defined Encrypt
  • You seem to be mixing comments and code without using comment syntax
    (comments need to be wrapped in /* */ or preceded with // )
  • Your if statements are not using brackets { } so the else statements do not make much sense.
  • You have code outside of the scope of main but not wrapped in any other function body.
  • It looks like you are trying to define local functions - but it is hard to tell with the prblems listed above.

this code is c++ and it should encrypt and decrypt strings
but i steel get errors in the code i just want to find out what is wrong
with this code

Did you investigate anything I mentioned?

include <iostream>
include <string.h>

using namespace std;

char clear [300];
char cipher[300];
int x;
int choice;

int main()
{
system("Color 0B");

int level1();
int level2();
int level3();
int level4();
int i;
char decrypt;

cout << "Enter a Sentence: ";
gets(clear);

cout << endl << "Choose method of encryption 1, 2, 3,  " << endl;
cout << "1. Plain Ceasar Cipher. " << endl;
cout << "2. Spaces. " << endl;
cout << "3. Vowels. " << endl << endl;
cin >> choice;

system("pause");

x = strlen(clear);//shows length of sentence input

if (choice == 1)
{
cout << endl << "You have chosen : Plain Ceasar Cipher " << endl;
level1();
}
else if (choice == 2)
{
cout << endl << "You have chosen option : Spaces " << endl;
level2();
}
else if (choice == 3)
{
cout << endl << "You have chosen option : Vowels " << endl;
level3();
}

cout << endl << endl << "Would you like to decrypt the code? (Y/N) ";
cin >> decrypt;

if (decrypt == 'y')
{
cout<< endl << "Original Sentence was: " << clear << endl << endl;
cout << "The Decrypted Sentence is : ";
level4();
}

system("pause");
return 0;

}

int level1()
{
int i;

for (i=0;i<=x-1;i++)
{
  cipher [i] = clear[i]+3;
  cout << cipher[i];
}

return 0;

}

int level2()
{
int i;

for (i=0;i<=x-1;i++)
{
    if (clear[i] != ' ')
    {
    cipher[i] = clear[i];
    cout << cipher [i];
    }
}
return 0;

}

int level3()
{
int i;

for (i=0;i<=x-1;i++)
{
    if (clear[i] == 'a'  || clear[i] == 'A' || clear[i] == 'e' || clear[i] == 'E' || clear[i] == 'i' || clear[i] == 'I' || clear[i] == 'o' || clear[i] == 'O' || clear[i] == 'u' || clear[i] == 'U' || clear[i] == ' ')
    {
    clear[i]=clear[i];
    }
    else             
    {
    cipher[i] = clear [i];
    cipher[i] = cipher [i] +3;
    cout << cipher [i];
    }
}
cout << cipher[i];
return 0;

}

int level4()
{
int i;
char a;

for (i=0;i<=x-1;i++)
{
  clear[i] = cipher [i]-3;
  cout << clear[i];
}

return 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.