0
我遇到格式問題。但是,我似乎無法讓它看起來合適。tippingtable2gui - 格式化問題C#
我被告知在進入嵌套while循環或僅使用for循環之前初始化tipRate。但仍然遇到格式問題。
這裏是我的代碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonCalc_Click(object sender, EventArgs e)
{
// Constants
const double TIPSTEP = 0.05;
const double DINNERSTEP = 10.00;
// Variables
double maxRate = Convert.ToDouble (maxTip.Text);
double lowRate = Convert.ToDouble (minTip.Text);
double minDinner = Convert.ToDouble (minPrice.Text);
double maxDinner = Convert.ToDouble (maxPrice.Text);
double dinnerPrice = Convert.ToDouble (minPrice.Text);
double tipRate;
double tip;
tipRate = lowRate;
label1.Text = "";
label6.Text = "";
label7.Text = "";
label9.Text = "Price";
for (tipRate = lowRate; tipRate <= maxRate; tipRate += TIPSTEP)
label1.Text = label1.Text + String.Format("{0, 8}", tipRate.ToString("F")) + "\t";
label1.Text = label1.Text + String.Format("{0, 8}", tipRate.ToString("C")) + "\t";
label8.Text="--------------------------------------------------------------------------------------";
while (dinnerPrice <= maxDinner)
{
label6.Text = label6.Text + String.Format("{0, 8}" + "\n", dinnerPrice.ToString("C")) + "\t";
while (tipRate <= maxRate)
{
tip = dinnerPrice * tipRate;
label7.Text = label7.Text + String.Format("{0, 8}", tip.ToString("F")) + "\t";
tipRate += 0.05;
}
dinnerPrice += DINNERSTEP;
tipRate = lowRate;
}
}
}
}
好的,是否可以修復輸出結果的格式?這確實有幫助,但我真的只需要弄清楚如何讓輸出正確對齊 –