开发者

C# calculating area and perimeter [closed]

It's difficult to tell what is being asked her开发者_运维百科e. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

so im using Microsoft Visual C# 2010 Express. im trying to make a program that calculates area and perimeter. i have 2 text boxes for length and width. i have 2 readonly text boxes for area and perimeter. so i put in the numbers for area and perimeter and i get the answers in the area and perimeter readonly boxes when i click the "calculate" button. what's the code for this calculation?


Well that would be simple. Using basic geometrical formulas: Area = height x width and Perimiter = (height + width) x 2

Then simply do this:

int pmtr = (Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text)) * 2;
int area = Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox2.Text);

textBox3.Text = pmtr.ToString();
textBox4.Text = area.ToString();

Also, you might want to look at TryParse to make the code a bit more stable and avoid exceptions on invalid values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜