我做的加密程序,我的教授告訴我,這個程序是正確的,但我在switch
陳述邏輯是錯誤的,因爲..我的教授要我一個輸入加密值之一把它放在一個變量第一然後在加密值顯示它..請幫助我..加密使用switch語句
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<windows.h>
#include<cstdlib>
main()
{
const char *stringlength;
char input[100];
int i;
cout<<"Input letters only:";
cin>>input;
stringlength=input;
cout<<"\nEncryption Value:";
for(i=0; i<strlen(stringlength); i++)
{
switch(input[i])
{
case 'a':cout<<"0";break;
case 'A':cout<<"1";break;
case 'e':cout<<"2";break;
case 'E':cout<<"3";break;
case 'i':cout<<"4";break;
case 'I':cout<<"5";break;
case 'o':cout<<"6";break;
case 'O':cout<<"7";break;
case 'u':cout<<"8";break;
case 'U':cout<<"9";break;
case 'B':cout<<"C";break;
case 'C':cout<<"D";break;
case 'D':cout<<"E";break;
case 'F':cout<<"G";break;
case 'G':cout<<"H";break;
case 'H':cout<<"I";break;
case 'J':cout<<"K";break;
case 'K':cout<<"L";break;
case 'L':cout<<"M";break;
case 'M':cout<<"N";break;
case 'N':cout<<"O";break;
case 'P':cout<<"Q";break;
case 'Q':cout<<"R";break;
case 'R':cout<<"S";break;
case 'S':cout<<"T";break;
case 'T':cout<<"U";break;
case 'V':cout<<"W";break;
case 'W':cout<<"X";break;
case 'X':cout<<"Y";break;
case 'Y':cout<<"Z";break;
case 'Z':cout<<"A";break;
case 'b':cout<<"c";break;
case 'c':cout<<"d";break;
case 'd':cout<<"e";break;
case 'f':cout<<"g";break;
case 'g':cout<<"h";break;
case 'h':cout<<"i";break;
case 'j':cout<<"k";break;
case 'k':cout<<"l";break;
case 'l':cout<<"m";break;
case 'm':cout<<"n";break;
case 'n':cout<<"o";break;
case 'p':cout<<"q";break;
case 'q':cout<<"r";break;
case 'r':cout<<"s";break;
case 's':cout<<"t";break;
case 't':cout<<"u";break;
case 'v':cout<<"w";break;
case 'w':cout<<"x";break;
case 'x':cout<<"y";break;
case 'y':cout<<"z";break;
case 'z':cout<<"a";break;
default : cout<<"\nInvalid Character!\n"; break;
}
}
getch();
return 0;
}
我能做些什麼呢?我的提示是我需要一個變量,我可以把所有的文本加密值,然後cout
一次。
從沒想過我會看到TURBOC++和C++ 11在同一標籤列表。 – StoryTeller
你知道如何迭代數組嗎?你知道如何將值放入數組嗎?有什麼問題? – Beta
只要你通過C++,你就不會像c那樣快速地陷入麻煩,但你只允許在switch語句中放置16384個case標籤。 (在C中,它的實現限制設置爲1023) – dhein