思路是把每个位上的数字单独求出来保存到变量中,然后判断每个变量不能是8,且和要能被8整除

using System;
namespace App1
{
class Program
{
static void Main(string[] args)
{
Console.Write("请输入一个4位数的卡号:");
string s = Console.ReadLine();
bool b1 = s.Length == 4;
bool b2 = true;
foreach (char x in s)
{
if (x >= '0' && x <= '9' && x != '8')
continue;
b2 = false;
break;
}
int sum = 0;
foreach (char x in s)
sum += x - '0';
bool b3 = sum % 8 == 0;
if (b1 && b2 && b3)
Console.WriteLine("恭喜,卡号为{0}的客户您中奖了。", s);
else
Console.WriteLine("出错:不是一个4位整数的卡号。");
}
}
}