代码进入看·· 这个对高手来说很垃圾哈··· 但只是能记录自己的.NET生涯哈·?~
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*------------------------------------------------
程序名:counter.cs
程序功能:计算器
制作者:ZHOULONG
代码行数:96行
制作时间:2007-10-24
---------------------------------------------------*/
using System;
![](/Images/OutliningIndicators/None.gif)
namespace Test
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
class Test
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
static void Main()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int count = 0;
while (count < 5) //设置循环5次
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.Clear();
int top = 0;
Console.Clear();
//绘制界面头部
string title = "四 则 运 算 计 算 器 V1.2";
Console.WriteLine("*".PadLeft(80, '*'));
Console.SetCursorPosition(30, ++top);
Console.WriteLine(title);
Console.SetCursorPosition(42, ++top);
Console.WriteLine("制作人:ZHOULONG");
Console.WriteLine("*".PadLeft(80, '*'));
Console.WriteLine(" 本程序还可以用{0}次\n",5-count);
try //如果用户输入有错,提示!
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine(" 请问你要做什么算法:\n");
Console.WriteLine(" 1 - 加 法 运 算");
Console.WriteLine(" 2 - 减 法 运 算");
Console.WriteLine(" 3 - 乘 法 运 算");
Console.WriteLine(" 4 - 除 法 运 算\n");
Console.Write(" 请 选 择:");
int x = int.Parse(Console.ReadLine());
switch (x) // 多选择控制语句。
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
case 1: // 用case来定义每一个选择项。
Counter1();
break;
case 2:
Counter2();
break;
case 3:
Counter3();
break;
case 4:
Counter4();
break;
default:
Console.WriteLine("出错,只能输入: 1, 2,3 or 4.");
break;
}
Console.WriteLine("感谢你使用本程序!\n按Enter继续计算!");
Console.ReadLine();
}
catch
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine("只能输入数字,谢谢!按Enter重新启动本程序!");
Console.ReadLine();
}
Console.Clear(); // 清屏操作。
count++;
}
}
private static void Counter1()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine("请输入加数:");
double a1 = double.Parse(Console.ReadLine());
Console.WriteLine("请输入另一个加数:");
double a2 = double.Parse(Console.ReadLine());
double aa = a1 + a2;
Console.WriteLine("结果为:\n\n{0} + {1} = {2}\n",a1,a2,aa);
}
private static void Counter2()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine("请输入被减数:");
double m1 = double.Parse(Console.ReadLine());
Console.WriteLine("请输入另一个减数:");
double m2 = double.Parse(Console.ReadLine());
double mm = m1 - m2;
Console.WriteLine("结果为:\n\n{0} - {1} = {2}\n",m1,m2,mm);
}
private static void Counter3()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine("请输入乘数:");
double r1 = double.Parse(Console.ReadLine());
Console.WriteLine("请输入另一个乘数:");
double r2 = double.Parse(Console.ReadLine());
double rr = r1 * r2;
Console.WriteLine("结果为:\n\n{0} * {1} = {2}\n",r1,r2,rr);
}
private static void Counter4()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine("请输入被除数:");
double g1 = double.Parse(Console.ReadLine());
Console.WriteLine("请输入除数:");
double g2 = double.Parse(Console.ReadLine());
double gg = g1 / g2;
Console.WriteLine("结果为:\n\n{0} / {1} = {2}\n",g1,g2,gg);
}
}
}