抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >
语言:C#

搞了我一上午编出了个这玩意
TAOG的计算器ver2.0

源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;

namespace ConsoleApp6
{
class Program
{
static void Main()
{
Console.WriteLine("欢迎使用计算器v2.0");

A: Console.WriteLine("输入1进入程序,输入2查看更新内容\n");
int first;
try//运行可能会出错的代码
{
first = int.Parse(Console.ReadLine());//接收用户所输入的值,并将其转换为int型
}
catch (Exception)//捕捉错误
{
Console.WriteLine("请输入数字");
goto A;
}

if (first == 1|| first == 2)//判断输入的数字是否为1或2
{

if (first == 1)//如果是1
{
goto B;
}

if (first == 2)//如果是2
{
Console.WriteLine("1.丰富了内容\n2.更新了更优秀的运算逻辑\n3.增加排错提示\n");
goto A;
}


}
else//如果不是1或2
{
Console.WriteLine("请输入正确的数字\n");
goto A;
}


B: Console.WriteLine("请输入第一个数字");
int second;
try
{
second = int.Parse(Console.ReadLine());//同上
}
catch (Exception)
{
Console.WriteLine("请输入数字\n");
goto B;
}
C : Console.WriteLine("请输入运算符,+-*/\n");
string third;
third = Console.ReadLine();
if (third == "+" || third == "-" || third == "*" || third == "/")//判断输入的运算符是否合法
{
goto D;
}
else//如果不合法的话...
{
Console.WriteLine("请输入正确的运算符\n");
goto C;
}
D: Console.WriteLine("请输入第二个数字");
int fourth;
try
{
fourth = int.Parse(Console.ReadLine());//同上
}
catch (Exception)
{
Console.WriteLine("请输入数字\n");
goto D;
}
//判断输入的运算符
if(third == "+")
{
Add(second, fourth);
}
if (third == "-")
{
Minus(second, fourth);
}
if (third == "*")
{
Mul(second, fourth);
}
if (third == "/")
{
Div(second, fourth);
}

}
//运算
static void Add(int a , int b)
{
int c;
c = a + b;
Console.WriteLine("\n结果等于" + c);
Console.ReadKey();
}
static void Minus(int a, int b)
{
int c;
c = a - b;
Console.WriteLine("\n结果等于" + c);
Console.ReadKey();
}
static void Mul(int a, int b)
{
int c;
c = a * b;
Console.WriteLine("\n结果等于" + c);
Console.ReadKey();
}
static void Div(int a, int b)
{
int c;
c = a / b;
Console.WriteLine("\n结果等于" + c);
Console.ReadKey();
}
}
}

评论