using System;
using System.Collections.Generic;
using System.Text;
namespace AddMoney
{
/// <summary>
/// 此樣本是類比手機沖值過程
/// </summary>
class Program
{
static void Main(string[] args)
{
Console.WriteLine("歡迎使用全業務儲值服務!");
bool success = AddMoney(); // 儲值操作
if (success)
{
Console.WriteLine("儲值成功!");
}
else
{
Console.WriteLine("儲值失敗!");
}
Console.ReadLine();
}
// 類比儲值過程
private static bool AddMoney()
{
string input; // 使用者的輸入
string phoneNumber; // 手機號碼
int position; // 最後一個#的位置
Console.WriteLine("請輸入您的儲值卡號、密碼和要儲值的手機號碼,以#分隔:");
input = Console.ReadLine();
position = input.LastIndexOf("#");
if (position > 0)
{
phoneNumber = input.Substring(position+1);
Console.WriteLine("您要儲值的手機號碼是:{0}",phoneNumber);
Console.WriteLine("確認儲值請按1,取消請按其他鍵。");
if (Console.ReadLine() == "1")
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
}