2016-04-13 7 views
-1

私はコードの大部分を終えましたが、月額支払いの計算を開始する場所と方法はわかりません。 私は入力をローカル変数に渡しました。 私は底部で計算を試みました。だから私を助けてください。C#/ WPF私はどのように計算するのか分からない住宅ローン計算機の月額支払

+0

このコードには何が問題なのですか?エラーまたは例外が発生していますか?関連するコードだけで質問を編集してください。 –

+0

私はどのように戻って投稿を編集するのか分かりませんが、すべての値を入力して[送信]ボタンをクリックすると何も表示されません。私の計算は間違っている(書かれているように)。 – Sam2704

+0

'else'ステートメントの後に3行の角かっこはありません。したがって、実行は決して計算や' MessageBox.Show(MonthPay) '行には届きません。 IDEが到達不能コードに関する警告を表示している可能性があります。 –

答えて

1

あなたはMVVMパターンを使用していないので、あなたのコールバックは、WPFのオートコンプリートbehind'.Use「コードにする必要があります上:

MortgageCalculator.MainWindow

<Button Click="HERE!!!"> 
    <Button.Effect> 
     <DropShadowEffect BlurRadius="2" Color="#FF7E7979" ShadowDepth="2"/> 
    </Button.Effect> 
</Button> 

これは、コールバックを作成します。コードの後ろに(そしてあなたがしたようにウィンドウではなく)。 MortgageCalculator.MainWindow.xaml.csで :コメントアウトまたは移動されたreturn文の

/// <summary> 
/// Interaction logic for MortgageCalculator.xaml 
/// </summary> 
public partial class MortgageCalculator : UserControl 
{ 
    public MortgageCalculator() 
    { 
     InitializeComponent(); 
    } 


    private void somecallback(object sender, RoutedEventArgs e) 
    { 
    } 
} 
0

をメモします。また、お支払い計算の修正バージョン:

private void btnsubmit_Click(object sender, RoutedEventArgs e) 
{ 

    { 
     double monthlypayment = 0; 

     //Tryparse for principal amount with error Red texbox 
     if (String.IsNullOrEmpty(txtprincipal.Text) || !double.TryParse(txtprincipal.Text, out principal)) 
     { 
      txtprincipal.BorderBrush = new SolidColorBrush(Colors.Red); 
      return; 
     } 
     else 
      txtprincipal.BorderBrush = new SolidColorBrush(Colors.Black); 



     //Validate radio button 
     if (rad10years.IsChecked.Value) 
     { 
      years = 10; 
      //return; 
     } 
     else if (rad20years.IsChecked.Value) 
     { 
      years = 20; 
      //return; 
     } 
     else if (rad30years.IsChecked.Value) 
     { 
      years = 30; 
      //return; 
     } 
     else if (radother.IsChecked == true) 
     { 
      if (!double.TryParse(txtother.Text, out years)) 
      { 
       MessageBox.Show("Not a Valid year."); 
       return; 
      } 
      //return; 
     } 
     else 
     { 
      MessageBox.Show("Please select number of years."); 
      stkrdobtns.Background = new SolidColorBrush(Colors.Red); 
      return; 
     } 

     //monthlypayment = ((principal * rate)/1200)/Math.Pow(1 - (1.0 + rate/1200), (-12.0 * years)); 

     var r = rate/1200.0; 
     var n = years * 12.0; 
     monthlypayment = principal * ((r * Math.Pow((1 + r), n))/(Math.Pow(1 + r, n) - 1)); 
     string MonthPay = string.Format("The amount of the monthly payment is: {0:c}", monthlypayment); 
     MessageBox.Show(MonthPay); 
    } 
} 
関連する問題