tippingtable2gui -格式化问题c#

本文关键字:问题 格式化 tippingtable2gui | 更新日期: 2023-09-27 18:14:11

我对格式有问题。然而,我似乎无法使它看起来合适。

我被告知在进入嵌套while循环之前初始化tipRate,或者只使用for循环。但是我仍然对格式有问题。

应该是什么样子

我的是什么样子

我的代码

    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;
            }
            }
        }
    }

tippingtable2gui -格式化问题c#

好吧,您应该用伪代码写出来,然后将伪代码转换为实际代码。你想循环遍历所有可能的价格,对于每个价格循环遍历所有可能的小费百分比。在哪里"初始化"变量是很重要的。

initialize dinnerprice, maxDinner and maxTip
while dinnerprice <= maxDinner
begin
    set the tiprate to minimum  (This needs to be done at the start of every dinnerprice)
    while tiprate <= maxtiprate
    begin
        calculate tip
        print the tip in the appropriate place
        increment the tiprate
    end
    increment the dinnerprice
end