変数番号が0のときに私のプログラムがなぜ動いているのか教えてもらえますか?それ以上の質問や情報の入力をせずに停止してはいけませんか?変数が0のときにプログラムが実行されるのはなぜですか?
元のプログラムはwhile文を使っていました....教授はそれをdo文に変更するように頼んだ。整数を求めた後に0を入力した場合、そこで停止してはいけませんか?代わりに、2番目の質問をします。
数値が0ではない間にこれを行うと、数字が0のときに何が行われるのですか?
おかげ
#include <iostream>
using namespace std;
int main() {
int number, product = 1, count = 0;
cout << "Enter an integer number to be included in the product" << endl << "or enter 0 to end the input: ";
cin >> number;
do {
product = product * number;
count++;
cout << "Enter an integer number to be included in the product" << "or enter 0 to end the input: ";
cin >> number;
} while (number != 0);
if (count > 0) {
cout << endl << "The product is " << product << "." << endl;
}
}
このような問題を解決する正しいツールは、デバッガです。スタックオーバーフローを尋ねる前に、コードを一行ずつ進める必要があります。詳しいヘルプは、[小さなプログラムをデバッグする方法(Eric Lippert)](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)を参照してください。最低限、問題を再現する[最小、完全、および検証可能](http://stackoverflow.com/help/mcve)の例と、その問題を再現するためのデバッガ。 –
http://en.cppreference.com/w/cpp/language/do – juanchopanza
Do-whileはおそらくあなたがここで探しているループではありません – Bettorun