为什么这个表不能正确执行? [英] Why won't this table execute correctly?

查看:53
本文介绍了为什么这个表不能正确执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是整个代码,应该列出价格这个词,然后是小费率。这个词应该在哪里,但它没有把小费率放在...任何建议?

This is the entire code that is supposed to list the word 'Price" followed by tip rates. The word is where it should be but it doesn't put the tip rates in ...any suggestions?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace TippingTable.cs
{
    class Program
    {
        static void Main(string[] args)
        {
            double dinnerPrice = 10.00;
            double tipRate;
            double tip;
            const double LOWRATE = 0.10;
            const double MAXRATE = 0.25;
            const double TIPSTEP = 0.05;
            const double MAXDINNER = 100.00;
            const double DINNERSTEP = 10.00;
 

            Console.Write("   Price");
            for(tipRate = LOWRATE; tipRate <= MAXRATE; tipRate +=
                TIPSTEP)
            Console.Write("{0, 8}", tipRate.ToString("F"));
            Console.WriteLine ();
            Console.WriteLine("-----------------------------------------");
 
            tipRate = LOWRATE;
            while (dinnerPrice <= MAXDINNER)
            {
                Console.Write("{0, 8}", dinnerPrice.ToString("C"));
                while (tipRate <= MAXRATE)
                {
                    tip = dinnerPrice * tipRate;
                    Console.Write("{0, 8}", tip.ToString("F"));
                    tipRate += 0.05;
                }
                dinnerPrice += DINNERSTEP;
                tipRate = LOWRATE;
                Console.WriteLine ();
            }
        }
            
            
 

 

 

        }
    }

推荐答案

您必须使用调试器来查找 - 没有您的数据,我们无法开始查看。



所以放一个断点:

You will have to use the debugger to find out - without your data there is nothing we can start to look at.

So put a breakpoint on the line:
Console.Write("   Price");

并在调试器中运行您的应用。

当它达到您设置的断点时,它将停止并等待您告诉它该做什么。

现在您可以查看变量及其内容,单步执行程序并完全遵循它的内容做什么和为什么。



听起来可能很复杂,但它真的非常简单(或者无论如何都是调试的基础),这是一项非常值得开发的技能!

And run your app in the debugger.
When it hits the breakpoint you set, it will stop and wait for you to tell it what to do.
Now you can look at variables and their content, single step your program and follow exactly what it is doing and why.

It may sound complicated, but it's really very simple (or the basics of debugging are, anyway) and it's a skill that is well worth developing!


因为您使用 Console.Write inste广告 Console.WriteLine ,因此所有输出都打印在同一行。
Because you are using Console.Write instead of Console.WriteLine, so all the output is printed on the same line.


这篇关于为什么这个表不能正确执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆