There is little mistakes in this program. I couldnot understand.
may be you can see.
For example ı can not solve exit problem in menu function
#include <iostream>
using namespace std;
void encyrpt(void);
void decyrpt(void);
void menu (void) // this function provide to be reached to menu
{
char a;
cout<<"(E/e) Encryption"<<endl;
cout<<"(D/d) Decryption"<<endl;
cout<< "(Q/q) Quit"<<endl;
cout<<"Enter operation code :";
do
{
cin>>a;
if ( a!='e' || a!='d' || a!='E' || a!='D') // with respect to election , program will be redirecting encyrpt ot decyrpt
cout<<"/n you entered an invalid operation code"<<endl;
else if ( a=='e' || a=='E')
encyrpt();
else if (a=='d' || a=='D')
decyrpt();
}
while (a!='q' || a!='Q')
return; // when key is q , it should quit program
}
void encyrpt (void)
{
int num,a,b,c,d,e,f;
char g,h;
cout<<"the 4-digit integer to be encrypted"<<endl;
do
{
cin>>num;
if (num<=999 || num>=10000)
cout<<" You entered an invalid integer!"<<endl;
else
a=num/1000;
b=num%1000;
c=b/100; // this is encyription formula
d=b%100;
e=d/10;
f=d%10;
cout<<"Encrypted integer "<<a<<c<<e<<f<<endl;
cout<<"Do you want to encrypt another integer? (y/n) :"<<endl;
}
while (num<=999 || num>=10000);
do // if user enters wrong character, until user enters right character, program asks for right choice
{ //
cin>>h; //
if(h=='y') //
encyrpt(); //
else if (h=='n') //
menu(); //
}
while(h!='y' || h!='n');
}
void decyrpt(void) // decyrpt function
{
int num,a,b,c,d,e,f,m,n,r,k;
char h;
cout<<"the 4-digit integer to be decrypted"<<endl;
do
{
cin>>num;
if (num<=999 || num>=10000)
cout<<" You entered an invalid integer!"<<endl;
else
a=num/1000;
b=num%1000;
c=b/100;
d=b%100;
e=d/10;
f=d%10;
k=(10+f)/2;
r=( (10+e-f)%10);
n=( (10+c-f)%10);
m=( (10+a-f)%10);
cout<<"Decrypted integer is "<< m<<n<<r<<k<<endl;
cout<<"Do you want to encrypt another integer? (y/n) :"<<endl;
}
while (num<=999 || num>=10000);
do
{
cin>>h;
if(h=='y')
decyrpt();
else if (h=='n')
menu();
}
while(h!='y' || h!='n');
}
int main(void)
{
menu();
return 0;
}