私は授業のためのプログラムを作成しており、それをどのように働かせるかに関するアドバイスが必要です。私は、ユーザーが商品の価格を入力するよう求めているプログラムを持っています。最初の商品の価格を入力すると、次の価格を求められます。問題は私がdo-whileループで必要とすることです。 whileループの各インスタンスの後に入力されたアイテムの合計価格を取得しようとしています。私は配列やリストを使うことができるが、代入はこれを要求しないことを知っている。 アドバイスが役に立ちます。Do Whileループ練習/ wユーザー入力
ここにdo whileループのコードがあります。
public static void Main()
{
double cost;
int Items;
string counter;
string value;
string more;
double newtotal;
int loopcounter = 0;
//item cost
Console.WriteLine("Welcome to the Online Store");
Console.WriteLine("How many items are you buying?");
counter = Console.ReadLine();
Items = Convert.ToInt32(counter);
do
{
// buying items
Console.WriteLine("Enter the cost of your item one by one");
value = Console.ReadLine();
cost = Convert.ToDouble(value);
newtotal = +cost;
loopcounter++;
}
while (loopcounter < Items);
サイドノートをそれを維持します、それは 'newtotal + = cost'でなければなりません。これは、合計をコストに設定し、変数に追加するのではなく – pinkfloydx33