Hello everyone. I have been given an assignment that I've been struggling with.
The idea is, the user needs to input a four digit number. If the number input only has 1-3 digits, the program is to assume that the empty spaces in front of those numbers are 0.
If it has 5+ digits, it will return an error message.
Then, each digit of the number is replaced by (the sum of the digit with the number 7) modulo 10.
The three functions I am required to use are:
int readNumber(); //function to read a four-digit number
int encrypt(int data); //function to encrypt data
int decrypt(int data); //function to decrypt data
It would be extremely helpful for someone to look over what I have so far and provide some input on how to move forward.
I have a decent amount complete, but I keep getting "too few arguments to function" errors for my encrypt and decrypt functions.
Example:
When the user selects to Encode or decode a number:
Please select one of the following:
1. Encode a number.
2. Decode a number.
Enter choice: 1
Enter the four digit number: 7645
The encrypted number is: 2134
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
int encrypt(int Num1, int Num2, int Num3, int Num4);
int decrypt(int Num1, int Num2, int Num3, int Num4);
int readNumber();
char choice;
int main()
{
cout << endl;
cout << "Please select one of the following: " << endl;
cout << "1. Encrypt a number " << endl;
cout << "2. Decrypt a number " << endl;
cout << endl;
cout << "Enter choice: ";
cin >> choice;
cout << endl;
if (choice == '1')
{
readNumber();
encrypt();
}
else if (choice == '2')
{
readNumber();
decrypt();
}
else
{
cout << "Invalid choice. Try again. " << endl;
return main();
}
}
int readNumber()
{
int number;
int Num1,Num2,Num3,Num4;
cout << "Enter the four digit number: ";
cin >> number;
cout << endl;
Num1 = number / 1000;
Num2 = number / 100 - 10*Num1;
Num4 = number%10;
Num3 = (number%100 - Num4) / 10;
return 0;
}
int encrypt(int Num1, int Num2, int Num3, int Num4)
{
cout << "The encrypted number is: "
<< (Num4 + 7)%10
<< (Num3 + 7)%10
<< (Num2 + 7)%10
<< (Num1 + 7)%10
<< endl;
return 0;
}
int decrypt(int Num1, int Num2, int Num3, int Num4)
{
cout << "The decrypted number is: "
<< (Num1 + 3)%10
<< (Num2 + 3)%10
<< (Num3 + 3)%10
<< (Num4 + 3)%10
<< endl;
return 0;
}
|