所以我试图加密一个四位数的整数,在数字中加上七,然后将整数除以十。在我的计划中,我分别取每个数字,然后我需要将整个数字除以十。我怎样才能将所有单独的int整合成一个四位数字?加密数字C++
#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选择什么样的输入? – Mahesh
“将它们分在一起”是什么意思? – Mat
这是功课吗?如果是这样,请相应标记。 – Uffe