2017-10-10 12 views
0

ユーザーが「計算ボタン」に当たったときにコードを印刷するのに問題があります。 2回目にクリックすると、印刷物が出力されます。何かご意見は?私は私のif/elseステートメントと論理エラーを想定していますが、私のprintステートメントはどこにあるのですか?私は、入力を解析し、私の計算を行うために戻って値を送信する別のメソッドを構築する必要がありますか?2回目の繰り返しまではコードを取得できません

private void calcButton_Click(object sender, EventArgs e) 
    { 
//declare drink variables 

     double cappuccino = 3.25, espresso = 3.5, latte = 3.00, icedLatte = 3.75, icedCappuccino = 3.75; 

     //declare coffee bag variables 

     double pounder = 9.99, half = 5.99, third = 3.99; 

     //other local variables 

     double quantity; 


     //parse input from user on quantity of goods 
     double.TryParse(quantityTextBox.Text, out quantity); 

     //series of else if statements used to determine which radio button is keyed by user 



     itemAmountLabel.Text = value.ToString("N"); 
     subTotal += value; 

     // surchargeCalc(surcharge); 

     //Calculate tax 
     tax = taxRate * (subTotal + totalSurcharge); 

     total = tax + subTotal + totalSurcharge; 

     subtotalLabel.Text = subTotal.ToString("N"); 
     totalLabel.Text = total.ToString("N"); 
     taxLabel.Text = tax.ToString("N"); 


     if (cappuccinoRadioButton.Checked) 
     { 
      value = quantity * cappuccino; 
      return; 
     } 

     else if (espressoRadioButton.Checked) 
     { 
      value = quantity * espresso; 
      return; 
     } 
     else if (latteRadioButton.Checked) 
     { 
      value = quantity * latte; 
      return; 
     } 
     else if (icedLatteRadioButton.Checked) 
     { 
      value = quantity * icedLatte; 
      return; 
     } 
     else if (icedCappuccinoRadioButton.Checked) 
     { 
      value = quantity * icedCappuccino; 
      return; 
     } 
     else if (onePoundBagRadioButton.Checked) 
     { 
      value = quantity * pounder; 
      return; 
     } 
     else if (halfPoungBagRadioButton.Checked) 
     { 
      value = quantity * half; 
      if (surchargeCheckBox.Checked) 
      { 
       surcharge++; 
      } 
      return; 
     } 

     else 
     { 
      value = quantity * third; 
      if (surchargeCheckBox.Checked) 
      { 
       surcharge++; 
      } 

     } 
+0

Webフォーム、WPF、winforms?これはどのタイプのプログラムですか?残りのコードはどこにありますか? – Liam

+2

コードに印刷ステートメントがないため印刷されません。 –

+0

これは 'calcButton_Click'のコードですか?私は閉じ括弧が表示されません。 – AgapwIesu

答えて

1

あなたはここに値を書き出すように見える:

itemAmountLabel.Text = value.ToString("N"); 

あなたは、あなたのすべての計算を行う前に。

実際に計算が終わったら、メソッドの最後に出力を書き込む必要があります。

この行の前に戻ると、まだ書き込まれないように、あなたがこれを移動するときにあなたの返信文に注意してください。

すべてのリターンが大きなif-elseifブロックに含まれているため、それらを削除できます。

関連する問題