1
ユーザーが続行するかどうかの応答を入力すると、肯定的なユーザーの応答後に残りのプロンプトが表示されます。この制御文を組み込む前に、ループは各ユーザーの応答を待っていました。その後、プロンプトの残りのセットは、ユーザの入力に関係なくコンソールに出力されます。C++:制御文の後でループが異なる動作をする
元の機能を維持しながらコントロールステートメントを組み込むにはどうすればよいですか?
using namespace std;
int main(){
bool cont1, cont2;
string items [10];
float budget;
float prices [10];
int i;
string y, n;
for (i = 0; i < 10; i++){
cout << "Enter item name: "<<endl;
cin >> items[i];
cout << "Enter item price: "<<endl;
cin >> prices [i];
cout << "Enter another item? (y/n): "<<endl;
cin >> cont2;
if ((tolower(cont2)) == 'y'){
break;
}
else if ((tolower(cont2)) != 'n' && (tolower(cont2)) != 'y'){
cout << "Please enter y(es) or n(o)." << endl;
}
}
}