My programs encrypts 4digits and they are replaced with the result of adding 7 to the digit and getting the remainder after dividing the new value with 0. the 1st digit is then swap with the third and the second with the forth digit.
i succeeded in compiling this task:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>
using std::setw;
int main()
{
const int arraySize = 4;
int a[ arraySize ];
int n[ arraySize ];
You cant reverse it ,because you use modulo operator (%) . You cant be sure that , number was bigger than 10 or not.
So, you better change your encryption algorithm.(or formula)
if you add 7 to a digit, the reverse would be to subtract 7. But since negative numbers don't play well with the modulo operator, I would add 10-7:
original number: 2
(2 + 7) % 10 = 9
to reverse:
(9 + 10-7) % 10 = 2
However as Dufresne suggested, this doesn't work with multi digit integers. Therefore I wouldn't read the digits in as ints. For example if the user inputs the following 12 11 10 9, your program will give very strange results.
I would read the data in as chars. But that might be beyond the scope of this assignment, so whatever.