刚开始学习C#,在B站大学中学完了基础知识,开始自己写一个简易程序
该计算器能进行加减乘除运算,在输入数字不符合时就会让用户重新输入,输入运算符为除数时,若被除数为0的话就会进行错误提示,提示用户更改被除数
源代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace hello_C_
{
internal class jisuanji
{
static void Main(string[] args)
{
Console.WriteLine("这个是一个计算器\n可以运行加减乘除");
double num1 = GetUserInput("请输入第一个数字:");
string type;
do
{
Console.Write("请输入运算符 + - * / ");
type = Console.ReadLine();
} while (!IsValidOperation(type));
double num2;
do
{
num2 = GetUserInput("请输入第二个数字:");
if (type == "/" && num2 == 0)
{
Console.WriteLine("在除法运算中,除数不能为0。请重新输入。");
}
} while (type == "/" && num2 ==

最低0.47元/天 解锁文章
669

被折叠的 条评论
为什么被折叠?



