如何正确打印出最终结果? [英] How do I make the final result print out correctly?

查看:87
本文介绍了如何正确打印出最终结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个程序,使用以下比例将字母等级转换为数字等级



如果数字等级为90或以上,则为A

80或以上是B

70或以上是C

60或以上是D

且小于60它是F

通过控制台窗口输入您的数字等级

在单独的行上打印数字等级和字母等级



我觉得好像我让我的程序变得复杂并没有正确完成。打印输出不正确。显示:

write a program which converts a letter grade to numeric grade
using the following scale:
If numeric grade is 90 or over it is A
80 or over it is B
70 or over it is C
60 or over it is D
and less then 60 it is F
Enter your numeric grade through console window
print both Numeric grade and letter grade on separate lines

I feel as if I made my program to complicated and did not do it correctly. the printout is not correct. showing:

the value of A
90
the value of B
89
the value of C
79
the value of D
69
the value of F
59
the value of A   90
the value of B   89
the value of C   79
the value of D   69
the value of F   59
Press any key to continue

how do I simplify this and write it correctly. I do not want the answer directly just a guide for the right way to write this.

What I have tried:

<pre>odule Module1

    Sub Main()
        Dim A, B, C, D, F As Decimal
        ' A,B,C, D, F to convert numerically 
        Console.WriteLine("the value of A")
        A = Console.ReadLine()
        Console.WriteLine("the value of B ")
        B = Console.ReadLine
        Console.WriteLine("the value of C ")
        C = Console.ReadLine
        Console.WriteLine("the value of D ")
        D = Console.ReadLine
        Console.WriteLine("the value of F ")
        F = Console.ReadLine
        If A <> 90 Then A = 100
        If B <> 80 Then B = 89
        If C <> 70 Then C = 79
        If D <> 60 Then D = 69
        If F <> 0 Then F = 59

        Console.WriteLine("the value of A   " & A)
        Console.WriteLine("the value of B   " & B)
        Console.WriteLine("the value of C   " & C)
        Console.WriteLine("the value of D   " & D)
        Console.WriteLine("the value of F   " & F)

        Console.WriteLine("Press any key to continue")
        Console.Read()

    End Sub

End Module

推荐答案

引用:

编写一个转换a的程序字母等级到数字等级

write a program which converts a letter grade to numeric grade

我认为它应该说数字等级到字母等级 - 最后两行是关键:

I think it should say "numeric grade to a letter grade" - the last two lines are the key:

Quote:

通过控制台窗口输入您的数字等级

在单独的行上打印数字等级和字母等级

Enter your numeric grade through console window
print both Numeric grade and letter grade on separate lines



您的代码在正确的轨道上,但应该只有一个写和一开始读取提示并获得数字等级,最后两次写入以打印数字等级和字母等级。 if语句也很接近但需要更改以将数字等级转换为字母等级,而不是数字。还要仔细考虑F的一个,它与其他的不同。最后,考虑在你的if语句中使用 else ,因为你输入的每个数字等级都会产生F.如果你不确定为什么要使用调试器来逐步执行代码,它将变得明显是什么正在发生。



运行代码时你会看到如下内容:



输入数字等级: 84

84

B


Your code is on the right track but should only have one write and one read at the start to prompt for and get the numeric grade and two writes at the end to print the numeric grade and letter grade. The if statements are also close but need to be changed to convert the numeric grade to the letter grade, not a number. Also think carefully about the one for the F, it is different from the others. Finally, consider using else in your if statements, as written every numeric grade you enter will result in an F. If you are not sure why use the debugger to step through the code and it will become obvious what is happening.

When running the code you should see something like this:

Enter Numeric Grade: 84
84
B


这篇关于如何正确打印出最终结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆