所以我試圖加密一個四位數的整數,在數字中加上七,然後將整數除以十。在我的計劃中,我分別取每個數字,然後我需要將整個數字除以十。我怎樣才能將所有單獨的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