C++ C++;将跳过If-then-else条件
我正在为课堂写一个程序。它将一个句子翻译成伪日语(使用英语单词,但重新排列成语法顺序,并在相关单词中添加后缀) 库是有限的,我们不能使用函数或数组(低级类)。在这种情况下,我输入以下句子: “男人是红色的”(不带引号) 程序正确地解析单词。即每个单词周围没有空格 这是我的密码C++ C++;将跳过If-then-else条件,c++,C++,我正在为课堂写一个程序。它将一个句子翻译成伪日语(使用英语单词,但重新排列成语法顺序,并在相关单词中添加后缀) 库是有限的,我们不能使用函数或数组(低级类)。在这种情况下,我输入以下句子: “男人是红色的”(不带引号) 程序正确地解析单词。即每个单词周围没有空格 这是我的密码 if (word1 == "is") { question = "is-ka"; //If the second word is a subject, assign it and continue
if (word1 == "is")
{
question = "is-ka";
//If the second word is a subject, assign it and continue
//assigning the 3rd or 4th word as the object or adjective and kick out
//an error if not
if (word2 == string("man") || word2 == string("woman") || word2 == string("fish"))
{
subject = word2 + "-ga";
if (word3 == "man" || word3 == "woman" || word3 == "fish")
{
object = word3 + "-o";
sentence = subject + ' ' + object + ' ' + question;
cout << sentence << endl;
}
if (word3 == "red" || word3 == "short" || word3 == "strong")
{
adj = word3;
sentence = subject + ' ' + adj + ' ' + question;
cout << sentence << endl;
}
else
{
cout << "This is not a proper Eng-- sentence." << endl;
cout << "2 The sentence lacks a proper object." << endl;
}
}
我希望这就是你们一直在要求的。完整的代码并使用上面的输入编译
这里的问题是
word3
并没有以一种特别令人困惑的方式准确地包含它似乎包含的内容。读入它的代码如下所示
//Word 3
while(userSent[index] != ' ' && index <= sentLength)
{
word3 += userSent[index];
index++;
}
//Word 3
while(userSent[index]!=''&&index变量是如何声明的?它们声明为Strings请提供一个包含示例输入的自包含编译示例,否则我们如何轻松调试它?我提供了我得到的示例输出。我包括woman和fish,因为这些都是规范库中可能的名词。对我来说很好:Mike,你这个肮脏的fr他是个天才。
//Word 3
while(userSent[index] != ' ' && index <= sentLength)
{
word3 += userSent[index];
index++;
}