将百分制转换为五分制,如果输入的百分制成绩超出0~100时,程序抛出异常。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace CSharp
{
class Program
{
static void Main(string[] args)
{
while (true)
{
double num, num2;
string s;
Console.WriteLine("输入:x%,例如40%");
s = Console.ReadLine();
s = s.Substring(0, s.Length - 1);
num = double.Parse(s);
num2 = (5 * num) / 100;
if (num > 100 || num < 0)
{
try
{
throw new Exception();
}
catch (Exception ex) {
Console.WriteLine("error");
}
}
else
Console.WriteLine(num2 + "/5");
}
Console.ReadKey();
}
}
}