這裡是一個圖書管理系統,只是簡單的做一個形式,僅用於新手聯絡或者考試題複習,線上新手,輕噴謝謝合作 d=====( ̄▽ ̄*)b
C#可以直接複製,新手建議拿來練習,不要Ctrl+C,歡迎大家借鑑,互相學習。
下面是圖書管理系統詳細程式碼以及執行結果👇
//c#
using System;
using System.Drawing;
namespace library
{
class Program
{
public static int money = 0;
static void Main(string[] args)
{
Console.WriteLine("=========================================");
Console.WriteLine("\t ***** 歡迎光臨 ***** \t");
Console.WriteLine("\t **** 老李的書屋 **** \t");
Console.WriteLine("=========================================");
Console.WriteLine("下面由自動機器人為您服務,購買請輸入編號:");
Console.WriteLine("A.綠野仙蹤(59元)\t B.茶花女(46元)\t C.失格(72元)");
string s;
int user = 0;
do
{
s = Console.ReadLine();
switch (s)
{
case "A":
Console.WriteLine("已選擇綠野仙蹤,價格59");
user = user + 59;
Console.WriteLine("共" + user + "元,輸入0結算");
break;
case "B":
Console.WriteLine("已選擇茶花女,價格46");
user = user + 46;
Console.WriteLine("共" + user + "元,輸入0結算");
break;
case "C":
Console.WriteLine("已選擇失格,價格72");
user = user + 72;
Console.WriteLine("共" + user + "元,輸入0結算");
break;
case "0":
Console.WriteLine("共計消費金額{0}元",user);
break;
default:
Console.WriteLine("對不起,輸入有誤,請重新選擇:");
Console.WriteLine("A.綠野仙蹤(59元)\t B.茶花女(46元)\t C.失格(72元)");
break;
}
} while (s != "0");
if(money < user)
{
Console.WriteLine("對不起,您的餘額不足,請充值:");
Top();
for(; money < user;)
{
Console.WriteLine("對不起,充值金額不足,當前消費{0},餘額{1},請繼續充值",user, money);
Top();
}
}
else
{
money = money - user;
Console.WriteLine("共花費金額為:" + user);
Console.WriteLine("消費餘額為:" + money);
}
money = money - user;
Console.WriteLine("充值完成,購買完成,購買消費{0}元,消費後餘額{1}元", user, money);
Console.WriteLine("點選任意鍵退出系統");
Console.ReadKey();
}
private static void Top()
{
string i;
Console.WriteLine("餘額查詢請按:1");
Console.WriteLine("充值餘額請按:2");
do
{
i = Console.ReadLine();
switch (i)
{
case "1":
Console.WriteLine("餘額:" + money);
Console.WriteLine("輸入0退出");
continue;
case "2":
Console.WriteLine("請輸入充值的金額:");
int a = int.Parse(Console.ReadLine());
money = money + a;
Console.WriteLine("充值後餘額為" + money);
Console.WriteLine("輸入0退出");
break;
default:
Console.WriteLine("對不起,輸入有誤,請重新輸入:");
continue;
}
} while (i == "0");
}
}
}
執行結果如下👇
感謝大家的關注,博主在這裡獻給大家香吻一枚💋