住院:我找不到我的CalcTotalChargs未被识别的原因

时间:2016-03-07 00:03:59

标签: c# linq variables calculator

这应该工作,因为尽管被声明为最后一个私有双,C#的模块化应该允许第一个CalcTotalChargs被识别。这阻止我成功运行程序

以下是我目前的代码:

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 Adam_Zeidan_HW7CH6_6_Hospital_Stay
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void calculateButton_Click(object sender, EventArgs e)
        {
            *label6.Text = "You will be paying: " +         **CalcTotalChargs()**.ToString("c");*
        }

        private int CalcStayCharges()
        {
            return (350 * int.Parse(textBox1.Text));        // Calculating     the amount of days by $350
        }
        private double CalcMiscCharges()
        {
            return double.Parse(textBox2.Text) + double.Parse(textBox3.Text) +    
                double.Parse(textBox5.Text) + double.Parse(textBox5.Text);          // Adding together the other values entered within the textboxes to add to the eventual total charge
        }
        private double CalcTotalCharges()
        {
            return CalcMiscCharges() + CalcStayCharges();       // Adding     the number value of the sum of the previous calculation to the sum of the 350 *     Number of days staying
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您的功能拼写错误,因此无法完成。

CalcTotalChargs().ToString("c")应为CalcTotalCharges().ToString("c")

使用下面的代码,问题应该解决。

    private void calculateButton_Click(object sender, EventArgs e)
    {
        label6.Text = "You will be paying: " +         CalcTotalCharges().ToString("c");
    }