附加信息:输入字符串格式不正确

本文关键字:字符串 格式 不正确 输入 信息 | 更新日期: 2023-09-27 18:06:38

我正试图让这个程序工作,但没有骰子。我觉得它很完美,但还是少了点什么。它应该根据购买的门票数量和类型显示门票的价格,然后显示所有门票的价格和总收入。

namespace stadiumApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void label7_Click(object sender, EventArgs e)
        {
        }
        private void calculateRevenue_Click(object sender, EventArgs e)
        {
           //assigns input to saved memory 
                string inputA="";
                string inputB ="";
                string inputC ="";
                double ticketsPurchasedB = double.Parse(inputB);
                double ticketsPurchasedA = double.Parse(inputA);
                double ticketsPurchasedC = double.Parse(inputC);
               //price of each ticket grade
                double priceA = 15;
                double priceB = 12;
                double priceC = 9;
                //calculations for each class
                double calcOutputA = priceA * ticketsPurchasedA ;
                string outputA = calcOutputA.ToString();
            double calcOutputB = priceB * ticketsPurchasedB;
            string outputB = calcOutputB.ToString();
            double calcOutputC = priceC * ticketsPurchasedC;
            string outputC = calcOutputC.ToString();
           //calculations for total revenue
         double totalLabelHolder = calcOutputA + calcOutputB + calcOutputC;
           //display total 
            string totalLabel = totalLabelHolder.ToString();
      }
   }
}

附加信息:输入字符串格式不正确

您需要在表单上创建文本框并使用它们的值,而不是:

string inputA="";
string inputB ="";
string inputC ="";

每一行都会抛出一个错误(因为你不能将空字符串解析为双精度类型):

double ticketsPurchasedB = double.Parse(inputB);
double ticketsPurchasedA = double.Parse(inputA);
double ticketsPurchasedC = double.Parse(inputC);