【发布时间】:2011-10-15 14:56:55
【问题描述】:
所以我试图通过将七加到数字然后将整个数字除以十来加密四位整数。在我的程序中,我分别取每个单个数字,然后我需要将整个数字除以十。如何将所有单独的 int 组合成一个四位数?
#include "stdafx.h"
using namespace std;
int main()
{
//Define all variables needed
int a,b,c,d,enc,ext;
//Print dialog and input each single digit for the four number digit
cout << "Enter Your First Digit:" << endl;
cin >> a;
cout << "Enter Your Second Digit:" << endl;
cin >> b;
cout << "Enter Your Third Digit:" << endl;
cin >> c;
cout << "Enter Your Fourth Digit:" << endl;
cin >> d;
//Add seven to each digit
a += 7;
b += 7;
c += 7;
d += 7;
a /= 10;
b /= 10;
c /= 10;
d /= 10;
cout << "Your encrpyted digits:" << c << d << a << b <<endl;
cout << "Enter 1 to exit:" <<endl;
cin >> ext;
if (ext = 1) {
exit(EXIT_SUCCESS);
}
}
您可能已经注意到,我将每个数字分开。我需要一起做。然后我还创建了一个解密程序,我将在一个单独的程序中让我恢复到原始号码。
【问题讨论】:
-
if (ext == 1)。您需要使用==运算符而不是=运算符。=用于分配而不是用于逻辑比较。这个问题有点不清楚。你能解释一下你对 a,b,c,d 的输入范围是多少? -
“将它们分开”是什么意思?
-
这是作业吗?如果是这样,请相应地标记。
-
这是不是加密。这是不可逆的。
-
除以十后的余数就是这些人所说的取模! :P :D
标签: c++ encryption decimal