输入成绩输出等级c#
时间: 2024-06-09 15:01:27 浏览: 147
这段代码是一个C#程序,根据用户输入的分数输出对应的等级字母A,B,C,D,E。可以使用switch语句实现。具体代码如下:
```
Console.WriteLine("请输入学生成绩");
int score = Convert.ToInt32(Console.ReadLine());
switch (score / 10)
{
case 10:
case 9:
Console.WriteLine("等级为A");
break;
case 8:
Console.WriteLine("等级为B");
break;
case 7:
Console.WriteLine("等级为C");
break;
case 6:
Console.WriteLine("等级为D");
break;
default:
Console.WriteLine("等级为E");
break;
}
Console.ReadKey();
```
用户输入成绩后,程序会根据分数除以10的结果来判断等级。如果分数在90-100之间,输出A;如果在80-90之间,输出B;如果在70-80之间,输出C;如果在60-70之间,输出D;如果低于60,输出E。
相关问题
输入成绩输出等级c#用if实现
在C#中,你可以使用if-else语句来根据输入的成绩来确定等级。这里是一个简单的示例,假设我们有三个等级划分:优秀(90分以上)、良好(60-89分)和及格(60分以下):
```csharp
using System;
class Program {
static void Main() {
Console.Write("请输入您的成绩:");
int score = int.Parse(Console.ReadLine());
if (score >= 90) {
Console.WriteLine("等级:优秀");
} else if (score >= 60) {
Console.WriteLine("等级:良好");
} else {
Console.WriteLine("等级:及格");
}
}
}
```
在这个例子中,用户会被提示输入他们的成绩,然后程序会根据输入的分数判断并输出相应的等级。
c#输入成绩输出等级,超出0-100输出成绩错误
在 C# 中,你可以创建一个简单的控制台应用程序来接收用户输入的成绩并根据预设的评分标准输出相应的等级。如果输入的成绩超出了0到100的范围,程序会提示成绩错误。下面是一个基本的示例:
```csharp
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入成绩(0-100分):");
string input = Console.ReadLine();
int score;
if (int.TryParse(input, out score) && score >= 0 && score <= 100)
{
if (score >= 90)
Console.WriteLine("等级: A+");
else if (score >= 80)
Console.WriteLine("等级: A");
// 添加更多条件判断,直到grade E 或者未达到及格线
// ...
else if (score >= 60)
Console.WriteLine("等级: B+");
// ...
// 最低等级通常是 F
}
else
{
Console.WriteLine("成绩错误,输入值应在0到100之间.");
}
}
}
```
在这个例子中,我们首先获取用户的输入并尝试转换成整数。然后检查输入是否在有效范围内。如果在范围内,根据分数范围输出对应的等级;如果输入不在0到100之间,则显示错误消息。
阅读全文
相关推荐
![cs](https://img-home.csdnimg.cn/images/20250102104920.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)