我期待創建一個程序,詢問用戶5個不同的問題。每回答5個問題,程序會詢問用戶是否希望輸入一組新的答案。重複一組輸入,存儲和保存每個輸入。 C++
我將使用什麼函數來重新運行問題以及存儲和跟蹤它們的函數?
string Q1[10];
string Q2[10];
int Q3[10];
int Q4[10];
char newEntry;
do{
for(int i=0; i<11; i++){
cout << "Question 1: " << endl;
cin >> Q1[i];
}
for(int i=0; i<11; i++){
cout << endl << endl << "Question 2: " << endl;
cin >> Q2[i];
}
for(int i=0; i<11; i++){
cout << endl << endl << "Question 3: " << endl;
cin >> Q3[i];
}
for(int i=0; i<11; i++){
cout << endl << endl << "Question 4: " << endl;
cin >> Q4[i];
}
cout << "Would you like to repeat? Enter either 'y' or 'n': " << endl;
cin >> newEntry;
}while (newEntry=='y');
system("pause");
return 0;
}
是的我知道它只會按照指定重複10次。現在看起來工作正常,但是當我告訴程序停止輸入「n」來繼續進行重複問題時,是否需要添加一些內容?非常感謝 !! – noobuser333
@ noobuser333編輯代碼。刪除了'do ... while'循環。 – timrau