Encryption

a) Replace each digit with that digit plus 7.

b) Swap the first digit with the third.

c) Swap the second digit with the fourth. Then print the encrypted four-digit integer.

OK, I did the first one (I think), but I need help switching the first with the third digit and the second with the forth. Can anyone help me with this?


#include
void main()
{
cout<<"Enter a four-digit number to be encrypted:";
char a[4];
cin >> a;
int b[4];
b[0]=(int(a[2])-int('0')+7)%10;
b[1]=(int(a[3])-int('0')+7)%10;
b[2]=(int(a[0])-int('0')+7)%10;
b[3]=(int(a[1])-int('0')+7)%10;
cout<<"Encrypted number is:";
for(int i=0;i<4;i++){

}
}
Last edited on
[code] Your code goes here [/code]
1
2
char a[4];
cin >> a;

The array will end with a '\0', so you need to oversize it.

Do a swap function with an auxiliary (or use std::swap)
Can you show me what that looks like?
Anyone?
for swapping
int c;
c=b[0];
b[0]=b[2];
b[2]=c;
c=b[1];
b[1]=b[3];
b[3]=c;


and take the size of a 5.1 space for /0.you should declare a as: int a[5];
............................................................................
http://www.cprogramming.tk
Topic archived. No new replies allowed.