2016-11-19 14 views
1

私は授業のためのプログラムを作成しており、それをどのように働かせるかに関するアドバイスが必要です。私は、ユーザーが商品の価格を入力するよう求めているプログラムを持っています。最初の商品の価格を入力すると、次の価格を求められます。問題は私が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); 
+0

サイドノートをそれを維持します、それは 'newtotal + = cost'でなければなりません。これは、合計をコストに設定し、変数に追加するのではなく – pinkfloydx33

答えて

0

newtotal = + cost;ステートメントを実行中に:Console.WriteLine( "あなたの合計金額:{0}"、newtotal);

0

newtotal = + cost;間違っています 代わりにnewtotal + = cost;ループから出

移動

 Console.WriteLine("Enter the cost of your item one by one"); 

あなたは何度も何度も一つ一つを入力するように買い手を伝えるために持っていないので...

グッド

関連する問題