【发布时间】:2015-04-01 01:09:55
【问题描述】:
我的 C++ 程序有问题。我重新格式化并显示用户输入控制台的单词。如果用户输入:您好,我是 bob。用户将 bob 输入控制台后按 Enter。我将重新格式化并以新格式重新打印。问题是在输入该控制台行上的所有单词之前,我不想显示更多输入的消息。我当前的循环要么在每个单词之后显示输入请求,要么根本不显示它。这取决于我是否包含提示。我需要做一个while循环处理每个单词并将其输出并在最后一个单词之后停止。什么是布尔参数?我包含我的代码以供参考。
int _tmain(int argc, _TCHAR* argv[])
{
int b;
string input;
string output ;
int check = 1;
while (check){
cout << "Enter in one or more words to be output in ROT13: " << endl;
cin >> input;
while(my issue is here){
const char *word = input.c_str();
for (int i = 0; i < input.length(); i++){
b = (int)word[i];
if (b > 96){
if (b >= 110){
b = b - 13;
}
else {
b = b + 13;
}
output += ((char)b);
}
else
{
if (b >= 78){
b = b - 13;
}
else {
b = b + 13;
}
output += ((char)b);
}
}
cout << output << endl;
output = "";
cin >> input;
}
check = 0;
}
return 0;
}
【问题讨论】: