为什么我会收到错误“}预期”以及如何解决? [英] Why am I getting error "} expected" and how do I fix it?

查看:89
本文介绍了为什么我会收到错误“}预期”以及如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我一直在尝试在visual studio的2015应用程序文件夹中为迷你项目编写一些代码。该任务的目的是为热传导方程创建一个计算器。



在设法使用基础知识创建工作计算器后,我被告知尝试添加一个消息框,以便计算器的输入值无效。



我这样做是通过将输入值等同于-1.0E-99除非另有说明,但是,当我尝试在消息框语句中添加大括号前的大括号(第37行)出现了错误,读作}预期。



在查找并在代码中的任何地方添加大括号以试图摆脱它之后,我仍然不知所措。



有谁请帮我解决?我非常感谢您的任何建议。



非常感谢和许多亲切的问候



我尝试了什么:



Hi,

I've been trying to write some code in visual studio's 2015 applications folder for a mini project. The aim of the task is to create a calculator for the heat conduction equation.

After managing to create a working calculator using the basics, I was then told to try and add a message box for when the input values of the calculator are invalid.

I did this by equating the input values to -1.0E-99 unless otherwise stated, however, when I tried to add in a message box statement the curly bracket before it (line 37) came up with an error reading "} expected".

After looking it up and adding curly brackets everywhere in the code to try and get rid of it, I'm still at a loss.

Does anyone please have a solution for me? I would greatly appreciate any advice you might have.

Thank you very much and many kind regards

What I have tried:

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 Heat_conduction_calculator_9
{
    public partial class Form1 : Form
    {
        double A, q, -k, T1, T2, x1, x2, Z;

        public Form1()
        {
            InitializeComponent();

            Z = -1.0E-99;
                -k = A = T1 = T2 = x1 = x2 = Z;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            x1 = double.Parse(textBox1.Text);
            T1 = double.Parse(textBox2.Text);
            x2 = double.Parse(textBox3.Text);
            T2 = double.Parse(textBox4.Text);
            k = double.Parse(textBox5.Text);
            A = double.Parse(textBox6.Text);
            if ((A >= Z) && (-k >= Z) && (x1 >= Z) && (x2 >= Z) && (T1 >= Z) && (T2 >= Z)) ;
            {
                q = (-1 * k * A * (T2 - T1) / (x2 - x1));
                textBox7.Text = q.ToString();
} //-----> line 37
            else if ((A <= Z)|(-k <= Z)|(x1 <= Z)|(x2 <= Z)|(T1 <= Z)|(T2 <= Z));
            MessageBox.Show("Invalid Input");

        }
                
    }
}

推荐答案

            if ((A >= Z) && (-k >= Z) && (x1 >= Z) && (x2 >= Z) && (T1 >= Z) && (T2 >= Z)) ;
            {
                q = (-1 * k * A * (T2 - T1) / (x2 - x1));
                textBox7.Text = q.ToString();
} //-----> line 37
            else if ((A <= Z)|(-k <= Z)|(x1 <= Z)|(x2 <= Z)|(T1 <= Z)|(T2 <= Z));
            MessageBox.Show("Invalid Input");



2;在的末尾如果行是错误的,他们不是C / C ++,请删除它们。



这是链接到语言作者的C和C ++参考书。注意,C是C ++的祖先,所以知道C对C ++总是有用。

C编程语言 - 维基百科,免费的百科全书 [ ^ ]

https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2。 pdf [ ^ ]

http://www.ime.usp。 br / ~pf / Kernighan-Ritchie / C-Programming-Ebook.pdf [ ^ ]



C ++编程语言 [ ^ ]


The 2 ";" at the end of the if line are mistakesn they are not C/C++, remove them.

Here is links to references books on C and C++ by the authors of the languages. Note than C is the ancestor of C++, so knowing C is always useful with C++.
The C Programming Language - Wikipedia, the free encyclopedia[^]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf[^]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf[^]

C++ Programing Language[^]


你有两个问题:

你不能命名变量-k。如果你希望它是Z的负数,你只需要将它命名为K并将其设置为-Z。

其次如果语句没有;在他们的最后。这有效地结束了你的if语句。以下是应该做你想做的代码:



You have two problems:
You can't name a variable -k. If you want it to be the negative of Z you just have to name it K and set it to -Z.
Secondly if statements don't have a ; at the end of them. That is effectively ending your if statment. Here is code that should do what you want:

<pre>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 Heat_conduction_calculator_9
{
    public partial class Form1 : Form
    {
        double A, q, k, T1, T2, x1, x2, Z;

        public Form1()
        {
            InitializeComponent();

            Z = -1.0E-99;
            A = T1 = T2 = x1 = x2 = Z;
            k = -Z;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            x1 = double.Parse(textBox1.Text);
            T1 = double.Parse(textBox2.Text);
            x2 = double.Parse(textBox3.Text);
            T2 = double.Parse(textBox4.Text);
            k = double.Parse(textBox5.Text);
            A = double.Parse(textBox6.Text);
            if ((A >= Z) && (-k >= Z) && (x1 >= Z) && (x2 >= Z) && (T1 >= Z) && (T2 >= Z)) 
            {
                q = (-1 * k * A * (T2 - T1) / (x2 - x1));
                textBox7.Text = q.ToString();
            } //-----> line 37
            else if ((A <= Z) | (-k <= Z) | (x1 <= Z) | (x2 <= Z) | (T1 <= Z) | (T2 <= Z)) 
            MessageBox.Show("Invalid Input");

        }

    }
}


这篇关于为什么我会收到错误“}预期”以及如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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