ユーザーは入力を入力できるようにプログラムを作成して、簡単な数学の科目で助けを得ることができます。私はそれを作ったと思ったので、そこにいない科目に入学した場合は、以下のelse文で見られるように(そうではないと)言うでしょう。なぜ私はそれを実行するとき、入力の件名が正しい場合、それはまだ別のステートメントを含む任意のアイデア? http://prntscr.com/ey3qyhC++はelse文を無視します
search = "triangle";
pos = sentence.find(search);
if (pos != string::npos)
// source http://www.mathopenref.com/triangle.html
cout << "A closed figure consisting of three line segments linked end-to-end. A 3 - sided polygon." << endl;
search = "square";
pos = sentence.find(search);
if (pos != string::npos)
// source http://www.mathopenref.com/square.html
cout << "A 4-sided regular polygon with all sides equal and all internal angles 90°" << endl;
else
cout << "Sorry, it seems I have no information on this topic." << endl;
case 2:
break;
default:
cout << "Invalid input" << endl;
}
'search =" square ";'と 'case 2:'までのすべてを 'else'文に入れます。三角形が見つからない場合は四角形のみを探します。 –
正方形や三角形以外のオプションがありますが、あまりにも多くのコードを入れたくありませんでした。三角形や四角形などのすべての検索のifの後にelse文を置いて記述しますか? –
ifのすべてのコードがif文になるように変更することができれば(例えば 'search =" square "; pos = sentence.find(search); if(pos!= string :: npos)' into 'if(sentence.find(" square ")!= string :: npos)')、最初のif文の後のすべてのif文をelse if文に変更することができます。そうでなければ、それぞれがelseの中になければなりません。私は答えを書くだろう –