So, as part of my punishment homework for an online C class, I have to write a program that solves this assignment:
"Your application should read the four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer."
I had to re-read it slowly because the sentence following the colon is unintuitive. My professor gave me an example. He inputted the sequence "1234" which resulted in the encoded output, "0189".
The reason I'm struggling with this assignment is because I feel I lack the proper knowledge of arguments/statements/etc. at this point to code something like this. After all, we're only in chapter 3 and we've just learned control structures (specificially if, if...else, and while statements) and assignment/increment/decrement operators.
As I understand the problem, it can be broken down in pseudocode as follows:
Read a four digit integer;
Add 7 to each of the digits individually;
If( digit + 7 < 10 --> digit ) else( remainder of sum / 10);
Swap respective digits;
Print output;
If 1234 is used as an example:
1+7 = 8; store 8;
2+7 = 9; store 9;
3+7 = 10; store remainder = 0;
4+7 = 11; store remainder = 1;
Result is 8901 after first sequence of operations. Now swap the digits to get proper encoded output, 0189.
The major problem I have is that I have no idea how to store individual digits as their own variables.
Nothing in the chapter has even alluded to this. The only libraries we've included thus far in our programming assignments are <stdio.h> and <stdlib.h> (the latter for pausing the DOS window).
I'd appreciate if anyone could lend me any help.
"Your application should read the four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer."
I had to re-read it slowly because the sentence following the colon is unintuitive. My professor gave me an example. He inputted the sequence "1234" which resulted in the encoded output, "0189".
The reason I'm struggling with this assignment is because I feel I lack the proper knowledge of arguments/statements/etc. at this point to code something like this. After all, we're only in chapter 3 and we've just learned control structures (specificially if, if...else, and while statements) and assignment/increment/decrement operators.
As I understand the problem, it can be broken down in pseudocode as follows:
Read a four digit integer;
Add 7 to each of the digits individually;
If( digit + 7 < 10 --> digit ) else( remainder of sum / 10);
Swap respective digits;
Print output;
If 1234 is used as an example:
1+7 = 8; store 8;
2+7 = 9; store 9;
3+7 = 10; store remainder = 0;
4+7 = 11; store remainder = 1;
Result is 8901 after first sequence of operations. Now swap the digits to get proper encoded output, 0189.
The major problem I have is that I have no idea how to store individual digits as their own variables.
I'd appreciate if anyone could lend me any help.