三角计算器 [英] triangle calculator
问题描述
我正在制作计算器,以计算c面为设定长度的底数.计算器还将计算三角形的高度,面积和准直器.我面临的问题是我的程序无法运行,它显示花括号引起的预期问题. 我已经检查过,看我是否缺少支架,或者如果我有两个很多而找不到解决方案,那么将不胜感激.这是我的代码.
hi i am making calculator to calculate the base when side c is a set length. the calculator will also calculate the height, area and perimiter of the triangle. the issue i am facing is my program wont run it is showing a expected issue with a curly brace. i have checked to see if i was missing a brace or if i have one two many and cant find a solution any help would be greatly aprreciated. here is my code.
使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间P
{
公共局部类Paddycalc:表格
{
公共Paddycalc()
{
InitializeComponent();
}
int a = 0;
int b = 0;
int c = 0;
const int zero = 0;
bool fred = true;
private double bot(double a,double b,double c)//计算基数
{
const int two = 2;
double s =((a + b + c)/2);
return s;
}
private double area(double a,double b,double c)//面积计算
{
const int two = 2;
double s =(a + b + c)/2;
返回Math.Sqrt(s *(s-a)*(s-b)*(s-c));
}
private void button1_Click(对象发送者,EventArgs e)
{
if(string.IsNullOrWhiteSpace(SideA.Text)&& string.IsNullOrWhiteSpace(SideB.Text)&& string.IsNullOrWhiteSpace(SideC.Text))
{
MessageBox.Show(请为三角形边长插入一个值,尚未输入任何值.",
未插入三角形边长",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
SideA.Text = Convert.ToString(零);
SideB.Text = Convert.ToString(零);
SideC.Text = Convert.ToString(零);
}
其他
{
试试
{
a = int.Parse(SideA.Text);
b = int.Parse(SideB.Text);
c = int.Parse(SideC.Text);
}
赶上
{
MessageBox.Show(请仅在侧面字段中插入数字.",
输入了不可读的符号/文本.",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
SideA.Text = Convert.ToString(零);
SideB.Text = Convert.ToString(零);
SideC.Text = Convert.ToString(零);
fred = false;
}
}
如果(弗雷德==假)
{
}
其他
{
双hh =面积(a,b,c); //值hh等于面积
双倍高度=((hh)* 2/c); //高度是使用产生的hh值计算的
double per = a + b + c;
Cbase.Text = Convert.ToString(bot(a,b,c));
Area.Text = Convert.ToString(area(a,b,c));
Height.Text = Convert.ToString(height);
Perimiter.Text = Convert.ToString(per);
如果(string.IsNullOrWhiteSpace(Cbase.Text))
{
Cbase.Text = Convert.ToString(零);
Area.Text = Convert.ToString(零);
Height.Text = Convert.ToString(零);
Perimiter.Text = Convert.ToString(零);
}
其他
{
}
如果(string.IsNullOrWhiteSpace(SideC.Text))
{
}
其他
{
如果(double.IsNaN(height))
{
MessageBox.Show(请为三角形边长插入正确的值.不正确的三角形边长.",
不正确的三角形边长",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
Cbase.Text = Convert.ToString(零);
Area.Text = Convert.ToString(零);
Height.Text = Convert.ToString(零);
Perimiter.Text = Convert.ToString(零);
}
}
私有void Form1_Load(对象发送者,EventArgs e)
{
}
private void textBox4_TextChanged(对象发送者,EventArgs e)
{
}
私有无效pictureBox1_Click(对象发送者,EventArgs e)
{
}
}
}
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 P
{
public partial class Paddycalc : Form
{
public Paddycalc()
{
InitializeComponent();
}
int a = 0;
int b = 0;
int c = 0;
const int zero = 0;
bool fred = true;
private double bot(double a, double b, double c) //Calulations for the base
{
const int two = 2;
double s = ((a + b + c) / two);
return s;
}
private double area(double a, double b, double c) //Area calculations
{
const int two = 2;
double s = (a + b + c) / two;
return Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(SideA.Text) && string.IsNullOrWhiteSpace(SideB.Text) && string.IsNullOrWhiteSpace(SideC.Text))
{
MessageBox.Show("Please insert a value for triangle side length, No value has been entered.",
"Triangle Side Length not inserted",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
SideA.Text = Convert.ToString(zero);
SideB.Text = Convert.ToString(zero);
SideC.Text = Convert.ToString(zero);
}
else
{
try
{
a = int.Parse(SideA.Text);
b = int.Parse(SideB.Text);
c = int.Parse(SideC.Text);
}
catch
{
MessageBox.Show("Please insert only numbers into the side fields.",
"Unreadable symbol/text entered.",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
SideA.Text = Convert.ToString(zero);
SideB.Text = Convert.ToString(zero);
SideC.Text = Convert.ToString(zero);
fred = false;
}
}
if (fred == false)
{
}
else
{
double hh = area(a, b, c); // Value hh is equal to the area
double height = ((hh) * 2 / c); //height is calculated using the hh value produced
double per = a + b + c;
Cbase.Text = Convert.ToString(bot(a, b, c));
Area.Text = Convert.ToString(area(a, b, c));
Height.Text = Convert.ToString(height);
Perimiter.Text = Convert.ToString(per);
if (string.IsNullOrWhiteSpace(Cbase.Text))
{
Cbase.Text = Convert.ToString(zero);
Area.Text = Convert.ToString(zero);
Height.Text = Convert.ToString(zero);
Perimiter.Text = Convert.ToString(zero);
}
else
{
}
if (string.IsNullOrWhiteSpace(SideC.Text))
{
}
else
{
if (double.IsNaN(height))
{
MessageBox.Show("Please insert a correct value for triangle side length. Incorrect Triangle Side Length.",
"Incorrect Triangle Side Length",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
Cbase.Text = Convert.ToString(zero);
Area.Text = Convert.ToString(zero);
Height.Text = Convert.ToString(zero);
Perimiter.Text = Convert.ToString(zero);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
再次感谢
推荐答案
Hi Guyno,
Hi Guyno,
您忘记了使用两个花括号关闭button1_Click函数.试试这个:
You forgot to close button1_Click function with two curly braces. Try this one :
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 Project1
{
public partial class Paddycalc : Form
{
public Paddycalc()
{
InitializeComponent();
}
int a = 0;
int b = 0;
int c = 0;
const int zero = 0;
bool fred = true;
private double bot(double a, double b, double c) //Calulations for the base
{
const int two = 2;
double s = ((a + b + c) / two);
return s;
}
private double area(double a, double b, double c) //Area calculations
{
const int two = 2;
double s = (a + b + c) / two;
return Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(SideA.Text) && string.IsNullOrWhiteSpace(SideB.Text) && string.IsNullOrWhiteSpace(SideC.Text))
{
MessageBox.Show("Please insert a value for triangle side length, No value has been entered.",
"Triangle Side Length not inserted",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
SideA.Text = Convert.ToString(zero);
SideB.Text = Convert.ToString(zero);
SideC.Text = Convert.ToString(zero);
}
else
{
try
{
a = int.Parse(SideA.Text);
b = int.Parse(SideB.Text);
c = int.Parse(SideC.Text);
}
catch
{
MessageBox.Show("Please insert only numbers into the side fields.",
"Unreadable symbol/text entered.",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
SideA.Text = Convert.ToString(zero);
SideB.Text = Convert.ToString(zero);
SideC.Text = Convert.ToString(zero);
fred = false;
}
}
if (fred == false)
{
}
else
{
double hh = area(a, b, c); // Value hh is equal to the area
double height = ((hh) * 2 / c); //height is calculated using the hh value produced
double per = a + b + c;
Cbase.Text = Convert.ToString(bot(a, b, c));
Area.Text = Convert.ToString(area(a, b, c));
Height.Text = Convert.ToString(height);
Perimiter.Text = Convert.ToString(per);
if (string.IsNullOrWhiteSpace(Cbase.Text))
{
Cbase.Text = Convert.ToString(zero);
Area.Text = Convert.ToString(zero);
Height.Text = Convert.ToString(zero);
Perimiter.Text = Convert.ToString(zero);
}
else
{
}
if (string.IsNullOrWhiteSpace(SideC.Text))
{
}
else
{
if (double.IsNaN(height))
{
MessageBox.Show("Please insert a correct value for triangle side length. Incorrect Triangle Side Length.",
"Incorrect Triangle Side Length",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
Cbase.Text = Convert.ToString(zero);
Area.Text = Convert.ToString(zero);
Height.Text = Convert.ToString(zero);
Perimiter.Text = Convert.ToString(zero);
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
这篇关于三角计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!