C#操作碰到的问题
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _16
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double P = 0, r = 0;
int i = 0;
P = Double.Parse(textBox1.Text); //p为本金,r为年利率,下同
r = Double.Parse(textBox2.Text);
while (P < 2 * P)
{
i++;
P = P * Math.Pow(1 + r, 1);
}
textBox3.Text = i.ToString(); //这句修改一下.
}
private void button2_Click(object sender, EventArgs e)
{
double P = 0, r = 0;
int i = 0;
P = Double.Parse(textBox1.Text);
r = Double.Parse(textBox2.Text);
while (P < 1000000)
{
i++;
P = P * Math.Pow(1 + r, 1);
}
textBox4.Text = i.ToString();
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
}
}
上面是我打的窗体应用程序代码,可是我输出textbox3,4 的时候,发现数值很大,我把上面那句textBox3.Text = i.ToString(); 改为textBox3.Text = P.ToString();,发现输出的数值大的离谱,可是我觉得算法没什么问题。。。。纠结~!