私は今このコードを何時間も手伝ってきましたが、シンプルであっても、何が間違っているのか分かりません。それは論理ですか?または、問題は構文関連の問題ですか?カウンタとアキュムレータが動作せず、プログラムがクラッシュする。私は間違って何をしていますか?
私は、今月レースで個別に走ったキロメートルの数を入力するようにプログラムに指示します。 プログラムは、各レースでどのくらい走ったかを平均で伝えます。さらに騒ぎがなければ
は、ここでのコードは次のとおりです。ループ内
#include <stdio.h>
main()
{
int STOP_VALUE = 8 ; /* you pick this number - outside the valid data set */
int avg;
int currentItem;
float runningTotal = 0 ;
int counterOfItems = 0 ;
printf("Enter first item or 8 to stop: ");
scanf("%d", ¤tItem);
while (currentItem != 8) {
runningTotal += currentItem;
++counterOfItems;
printf("Enter next item or 8 to stop: ");
scanf("%d", currentItem);
}
/* protect against division by 0 */
if (counterOfItems != 0)
{
avg = runningTotal/counterOfItems ;}
else {
printf("On average, you've run %f per race and you've participated in %f running events. Bye! \n", runningTotal, counterOfItems);
}
return 0;
}
期待される出力は何ですか?代わりに何を得ますか? – DyZ