我試圖讓用戶選擇一個團隊(名稱包含在二維數組中),輸入所需的名稱/團隊,然後使用for循環比較用戶的輸入字與二維數組的話,並使用循環訪問數組中的每個字符串:將二維數組中的字符串與用戶輸入進行比較
#include <string>
#include <iostream>
#include <string.h>
int main(int argc, char* argv[]){
char cPlaychar[10][15] = { "BlackFurs", "EppiGods", "FairyDusters",
"Dwarvin", "Bloods", "Cryptics", "ArcAngels",
"DarkVillians", "Heroiteks", "Mass", };
char cKeyInput[15];
int results[10];
std::cout << "Please select a character
by typing the name and pressing enter" << std::endl;
std::cin >> cKeyInput;
for(int Array = 0; Array < 10; Array++){
switch (Array){
case '0':
results[0] = strcmp(cPlaychar[Array], cKeyInput);
if (results[0] = 0){
std::cout << "you have picked the first char";
}
break;
case '1': results[1] = strcmp(cPlaychar[Array], cKeyInput);
if (results[1] = 0){
std::cout << "you have picked the secound char";
}
break;
case '2':results[2] = strcmp(cPlaychar[Array], cKeyInput);
if (results[2] = 0){
std::cout << "you have picked the third char";
}
break;
case '3':results[3] = strcmp(cPlaychar[Array], cKeyInput);
if (results[3] = 0){
std::cout << "you have picked the fourth char";
}
break;
case '4':results[4] = strcmp(cPlaychar[Array], cKeyInput);
if (results[4] = 0){
std::cout << "you have picked the fith char";
}
break;
case '5':results[5] = strcmp(cPlaychar[Array], cKeyInput);
if (results[5] = 0){
std::cout << "you have picked the sixth char";
}
break;
case '6':results[6] = strcmp(cPlaychar[Array], cKeyInput);
if (results[6] = 0){
std::cout << "you have picked the seventh char";
}
break;
case '7':results[7] = strcmp(cPlaychar[Array], cKeyInput);
if (results[7] = 0){
std::cout << "you have picked the eighth char";
}
break;
case '8':results[8] = strcmp(cPlaychar[Array], cKeyInput);
if (results[8] = 0){
std::cout << "you have picked the ninth char";
}
break;
case '9':results[9] = strcmp(cPlaychar[Array], cKeyInput);
if (results[9] = 0){
std::cout << "you have picked the tenth char";
}
break;
} // end of switch
} // end of for
system("pause");
return 0;
}
您能否就您的問題添加具體問題? – Ziezi