【问题标题】:how do i get the array to cycle through so that the equation increases as does the monthly payment我如何让数组循环通过,以便等式随着每月付款的增加而增加
【发布时间】:2014-06-12 16:36:47
【问题描述】:

好的,这次我的问题更简单了,我重新编写了上一个问题的代码。现在我想弄清楚为什么我的每月账单清单没有增加。它应该在方程中增加。我尝试调试代码,但没有发现 ArrayMonths 数组是否没有循环。

 private void CalculateButton_Click(object sender, EventArgs e)
 {
string[] ArrayModel ={"CAMERO","IMPALA","TAHOE","SILVERADO","MUSTANG","TAURUS","EXPEDITION","F150",
                           "CAMERY","COROLLA","HIGHLANDER","TUNDRA","CHALLENGER","DART","DURANGO","RAM"};
double[] ArrayPrice ={33809,23300,49601,33383, 40585,32500,36245,46905,
                         48050,32560,42580,47530, 27995,20150,39750,45620};
double[] ArrayMonths = { 36, 48, 60, 72 };

string Model = ModelBox.Text.ToUpper();
double InterestRate = 0, TotalIntrst, MonthlyBill, Multiplier, Year, MaxYear = 4;
string UsrModelVehicle = ModelBox.Text.ToUpper();
double UsrScrInpt = Convert.ToDouble(CreditScoreBox.Text);
{
      if (UsrScrInpt <= 450)
    {
        for (int x = 0; x < ArrayModel.Length; ++x)
        {
            if (Model == ArrayModel[x])
            {
                foreach (double Months in ArrayDuration)
                {
                    ArrayModel[x] = Convert.ToString(ArrayLoan[x]);
                    InterestRate = 0.12;
                    TotalIntrst = InterestRate / 1200;
                    MonthlyBill = ArrayLoan[x] * TotalIntrst / (1 - (Math.Pow(1 / (1 + TotalIntrst), Months)));

                    UserMonthlyPayLabel.Text += string.Format("{0:C2}\n", MonthlyBill);
                    UserInterestLabel.Text = string.Format("{0:P2}", InterestRate);
                    InterestLabel.Text = string.Format("Interest");
                    PayNumbersLabel.Text = string.Format("36\n48\n60\n72\n");

【问题讨论】:

  • 您确定文本框中的模型在数组中吗?
  • ArrayMonths[y] 是我试图循环以提高月份,这将增加 MonthlyBill,然后再给我我的清单。我想。我希望。
  • 列表没有增加是什么意思?你期望看到什么?您是否希望标签文本随着 for 循环的每次迭代而更新?因为这不是一个很好的实现。
  • 我知道,但我才刚刚开始。所以可能不是很好。但我想要完成的是循环支付月薪并创建这样的列表--$1234.55-------------------------- -------------------------------------------------- -------------------------------------------------- -----------------$1234.55-------------------------------- -------------------------------------------------- -------------------------------------------------- ------------$1234.55-------- 但没有破折号。
  • 我刚刚得到它来做列表,但现在当我尝试选择不同的响应时它并不令人耳目一新。它只是添加到上面的列表中,而不是在我单击表单中的提交时放入新的总数。我尝试了很多类似 this.refresh 和其他一些没有运气的东西。

标签: c# arrays loops for-loop


【解决方案1】:
private void ReloadForm()//Here is the new method I was talking about.
{
 UserMonthlyPayLabel.ResetText();
  //this will reset the label I need for it to clear after change the model.
}
 private void CalculateButton_Click(object sender, EventArgs e)
  {
   DetailsGroup.Visible = true;
   PaymentGroup.Visible = true;

   string[] ArrayModel ={"CAMERO", "IMPALA", "TAHOE", "SILVERADO", "MUSTANG", "TAURUS",
                         "EXPEDITION", "F150", "CAMERY", "COROLLA", "HIGHLANDER",
                         "TUNDRA", "CHALLENGER", "DART", "DURANGO", "RAM"};
   double[] ArrayLoan ={33809, 23300, 49601, 33383, 40585, 32500, 36245, 46905, 48050,
                        32560, 42580,47530, 27995,20150,39750,45620};
   double[] ArrayDuration = { 36, 48, 60, 72 };
   string Model = ModelBox.Text.ToUpper();
   double InterestRate = 0, TotalIntrst, MonthlyBill;
   string UsrModelVehicle = ModelBox.Text.ToUpper();
   double UsrScrInpt = Convert.ToDouble(CreditScoreBox.Text);
   ReloadForm();
 //Here is where I call it to reset the label. It works pretty good.
   {
    if (UsrScrInpt <= 450)
    {
     for (int x = 0; x < ArrayModel.Length; ++x)
     {
      if (Model == ArrayModel[x])
      {
       foreach (double Months in ArrayDuration)
       {
        ArrayModel[x] = Convert.ToString(ArrayLoan[x]);
        InterestRate = 0.12;
        TotalIntrst = InterestRate / 1200;
        MonthlyBill = ArrayLoan[x] * TotalIntrst / (1 - (Math.Pow(1 / (1 +TotalIntrst),
                      Months)));
        UserMonthlyPayLabel.Text += string.Format("{0:C2}\n", MonthlyBill);
        UserInterestLabel.Text = string.Format("{0:P2}", InterestRate);
        InterestLabel.Text = string.Format("Interest:");
        PayNumbersLabel.Text = string.Format("36\n48\n60\n72\n");
       }
      }
     }
    }
   }
  }
 }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 2018-01-29
    • 2023-03-27
    • 2014-03-18
    • 1970-01-01
    • 2021-05-31
    • 1970-01-01
    相关资源
    最近更新 更多