实现计算器,实现加减乘除.

x563216750 2009-08-15 12:28:51
我想问可以用static函数做吗?
...全文
153 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
路过
Big_Elephant 2009-08-15
  • 打赏
  • 举报
回复
推荐你去看《大话设计模式》,第一个例子就是计算器。
而且不是你这种过程化的计算器。
x563216750 2009-08-15
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;

namespace test
{
class Program
{
static void Main(string[] args)
{
label:
Console.WriteLine("请逐一的输入你要计算的数字与运算符:");
int a=Convert.ToInt32( Console.ReadLine());
char sign = Convert.ToChar(Console.ReadLine());
int b= Convert.ToInt32(Console.ReadLine());
Console.Clear();
Console.WriteLine("输出的结果为:");
switch (sign)
{
case '+':
int c = Compute1(a, b);
Console.WriteLine("{0}+{1}={2}",a,b,c);
break;
case '-':
c = Compute2(a, b);
Console.WriteLine("{0}-{1}={2}", a, b, c);
break;
case '*':
c = Compute3(a, b);
Console.WriteLine("{0}*{1}={2}", a, b, c);
break;
case '/':
c = Compute4(a, b);
Console.WriteLine("{0}/{1}={2}", a, b, c);
break;
default:
Console.Clear();
Console.WriteLine("您输入的数据不正确,请重新输入一次.....");
break;

}
goto label;
//Console.ReadKey();
}

static int Compute1(int i, int j)
{
return i + j;
}
static int Compute2(int i, int j)
{
return i - j;
}
static int Compute3(int i, int j)
{
return i * j;
}
static int Compute4(int i, int j)
{
return i / j;
}

}
}
我已经想出...唉

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧