Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C使用双精度从一个范围输出字母等级_C#_Double - Fatal编程技术网

C# C使用双精度从一个范围输出字母等级

C# C使用双精度从一个范围输出字母等级,c#,double,C#,Double,看来我的老师想让全班用双人来解决这个问题。我很难把它拿下来。我肯定我错过了一些简单的事情,但我想看看别人怎么想 public char Test4(double grade) { // TODO: Write code here to compute an answer. // Return the answer from this function. // Read the lab document for de

看来我的老师想让全班用双人来解决这个问题。我很难把它拿下来。我肯定我错过了一些简单的事情,但我想看看别人怎么想

public char Test4(double grade)

    {
        // TODO: Write code here to compute an answer.
        //       Return the answer from this function.
        //       Read the lab document for detailed instructions.
    }
我尝试过使用if-else语句,但没有成功。我不知道怎么用双人床来做这个。请帮忙

谢谢

这是我尝试过的一个例子

if (grade >= 90 && grade <= 100)
        { 
            public char = 'A'
        }
        else if (grade >=80 && grade <90)
            {
            public char = 'B'
                        }
        return public char;
{
输出:

我已经把这个清理干净了。希望这有助于澄清问题

    public char Test4(double grade)
    {
        // TODO: Write code here to compute an answer.
        //       Return the answer from this function.
        //       Read the lab document for detailed instructions.
        if (grade >= 90.0)
        { return 'A'; }
        else
            if (grade >= 80.0)
        { return 'B'; }
        else
            if (grade >= 73.0)
        { return 'C'; }
        else 
            if (grade >=70.0)
        { return 'D'; }
        else
            if (grade >= 0)
        { return 'F'; }
        else
            if (grade <0 )
        { return '?'; }
        else
            if (grade > 100)
        { return '?'; }
    }

如果要返回public char,则需要就地返回它,或者将值存储在变量中

例1

if (grade >= 90)
{
    return 'A';
}
else if ....
{
    //copy for each letter grade above F
}
else 
{
    return 'F';
}
例2

char gradeLetter = 'F';
if (grade >= 90)
{
    gradeLetter = 'A';
}
else if ....
{
    //copy for each letter grade above F
}

return gradeLetter;

我不认为您使用编写好的Test4进行编译,并且运行的是旧的、未实现的Test4版本,因此没有结果。您有一个错误,我猜是:并非所有代码路径都返回一个值。要解决这个问题,在最后有一个总括——你不需要检查分数是否为100,只需返回即可


这是应该正确编译Test4的注意事项,您在Test5中有一个错误,也需要修复,并提供正确的结果。

哦,这是实验室文档中的信息。给定grade变量(表示学生的数字分数),确定他们应该收到的字母分数。返回正确的字母char作为此测试的结果。不要担心分数四舍五入。使用下表说明哪个字母对应哪个年级。请给我们看一份家庭作业问题的副本。你试过什么?为什么不起作用?请在问题中添加更多细节。您可以删除public char=该部分没有意义,可能会抛出错误,只需“返回”字母等级,即返回“A”。您可以对代码进行一些改进,但是如果您只返回语句中的字母等级,我可以想象您的if语句是有效的。{double A=grade=100;返回A;我将添加一个屏幕截图来显示我所做的事情和运行窗口。这里有一个链接。网站还不允许我嵌入一个图像。+1用于提及编译错误。还要注意的是,仅仅修复Test4方法中的错误是不够的-基本上你需要去掉所有的错误在编译新代码之前,请在错误列表中删除错误。是的!感谢您澄清,@Gus!所有错误都需要清除,以便您可以成功地重新编译。我认为它应该在Test5中,因为测试1-3正在运行,这应该可以修复Test4。假设我是正确的,您可以对Test5中的所有内容进行注释,并将return 0.0添加到c中ompileTest4@Katoshia,你得到答案了吗?
...
else if(grade >= 0)
{
    return 'F';
}
// if none of the if statements were hit, you have an incorrect grade value
return '?';