namespace 超市付款功能
{
class Program
{
static void Main(string[] args)
{
//会员满100元享受8折,非会员享受9折
Console.WriteLine("欢迎进入 [苏果超市自动付款]");
Console.Write("请输入您本次销售的金额:");
string jine = Console.ReadLine();//字符串是接受金额的
double jine1 = Convert.ToDouble(jine);//转换成double类型
Console.Write("您是否是本店会员,请输入(Y/N):");
string vip = Console.ReadLine();//接受
double result;//最后的付款金额
result = Pay(jine1, vip);//定义个一函数,让最后的付款金额能够调用这个函数
if (result > 0)
{
Console.WriteLine("您应付的金额为:{0}", result);
Console.WriteLine("谢谢光临!");
}
if (result < 0)
{
int status = 3;//定义个状态值,想利用for语句 最多执行三次,如果三次都输入错误就提示”稍后使用!“
for (int i = 0; i <= status; i++)
{
Console.Write("您输入的金额有误,请再次输入:");
jine = Console.ReadLine();
jine1 = Convert.ToDouble(jine);
Console.Write("您是否是本店会员,请输入(Y/N):");
vip = Console.ReadLine();
if (jine1 < 0)
{
Console.WriteLine("您输入的金额有误!");
Console.WriteLine("您还剩{0}次机会.", status - i - 1);
continue;
}
if (jine1 >= 0)
{
result = Pay(jine1, vip);
Console.WriteLine("您应付的金额为:{0}", result);
Console.WriteLine("谢谢光临!");
break;
}
}
}
}
//下列是函数:
static double Pay(double money, string vip)
{
double pay=0;//定义一个初始值:初始金额为0
if (vip == "Y" || vip == "y")//是会员 //如果是会员执行下面语句
{
if (money >= 100)
{
pay = money * 0.8;
return pay;
}
if (money < 100&&money>=0)
{
pay = money;
return pay;
}
if (money < 0)//防止超异常
{
pay = money;
return pay;
}
}
if (vip == "N" || vip == "n") //如果不是会员执行下面语句
{
if (money >= 100)
{
pay = money * 0.9;
return pay;
}
if (money < 100&&money>=0)
{
pay = money;
return pay;
}
if (money < 0)
{
pay = money;
return pay;
}
}
return pay;
}
}
}