实现效果:
屏幕出现提示:1、小杯3元;2、中杯4元;3、大杯5元,请输入对应数字选择...
用户输入数字则提示对应的结果:小杯,请支付3元;输入错误则默认中杯
下面是源代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleManyHellos
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("1=小杯3块,2=中杯4块,3=大杯5块");
Console.Write("你的选择?");
string s = Console.ReadLine();
int n = int.Parse(s);
switch (n)
{
case 1:
Console.WriteLine("小杯,请支付3块钱;");
break;
case 2:
Console.WriteLine("中杯,请支付4块钱;");
break;
case 3:
Console.WriteLine("大杯,请支付5块钱;");
break;
default:
Console.WriteLine("默认中杯,请付款4块钱;");
break;
}
Console.WriteLine("谢谢使用,祝您用餐愉快!");
}
}
}命令行效果截图:
![[C#小程序]命令行小程序之你要买大杯小杯还是中杯的实现代码 [C#小程序]命令行小程序之你要买大杯小杯还是中杯的实现代码](https://img.php.cn//upload/image/534/989/321/1490332291495696.jpg)
以上就是[C#小程序]命令行小程序之你要买大杯小杯还是中杯的实现代码的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号