プロジェクトの通貨値を格納するための配列と、現在の合計を保持するための double 変数を使用しています。コードをループで実行すると、ユーザー入力は配列に格納されず、実行中の合計には何も追加されません。ユーザーが-1を入力すると、ループを破って税金などを計算することになり、0が入力されると、最後の値が配列から削除されます。何をしても、これらの値を配列に入れることも、現在の合計を機能させることもできません。私が間違っているのはばかげていると確信していますが、それを見つけることはできません。
for(i = 0; i < priceArray.length; i++) {
System.out.print("\nEnter the price of the item...");
userInput = input.nextDouble();
if(userInput == -1) { // This will break the user out of the loop.
break;
}
else if(userInput == 0.0) {
System.out.println("You entered a zero, removing last price of $" + priceArray[i] + ".");
i--;
runningTotal =- priceArray[i];
}
else if(userInput > 0.0 && userInput < 2999.99) {
priceArray[i] = userInput;
priceArray[i] += runningTotal;
userInput += runningTotal;
System.out.println("You entered $" + userInput + ", total is $" + runningTotal + ".");
}
else {
i--;
System.out.println("Please enter a valid value under $2999.99.");
}// End if.
};// End for