如何修复下面的错误消息 [英] How do I fix the error message below

查看:87
本文介绍了如何修复下面的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  static void Main(string[] args)
        {

            //Variable Declaration
            string studentName = "";
            string studentGrade = "";
            int studentScore = 0;
            double studentPercent = 0;

            //Output Greeting
            Console.WriteLine("Welcome to the Grade Calculator!: ");
            Console.WriteLine("___________________________________________________________");
            Console.WriteLine("The purpose of the grade calculator is to help calculate your students grade for !");
            Console.WriteLine("___________________________________________________________");

            //Input inputs
            Console.WriteLine("Please enter in the students name: ");
            studentName =  (Console.ReadLine());
            Console.WriteLine("Please enter in the students score: ");
            studentScore = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("___________________________________________________________");

            //Do Calculations
if (studentScore < 0 || > 1000) - This line gives an error stating my > variable is not right. HOW DO I FIX THIS
            {
                Console.WriteLine("We apologize for the error. The value you entered in does not meet our criteria. Please enter in a number between 0 and 1000: ");
            }

            
            else

            {
                studentPercent = studentScore / 1000;
                studentPercent = Convert.ToDouble(Console.ReadLine());

                Console.WriteLine("You have entered in a good score: ");





我尝试了什么:



我尝试过使用visual studio建议但是它给了我更多错误。我只想要解决这个错误。我怎么做。



What I have tried:

I have tried using what visual studio suggested but it gives me more errors. I just want this one error to resolve. How do I do that.

推荐答案

这行if(studentScore< 0 ||> 1000)应该是



if(studentScore< 0 || studentScore> 1000)
This line if (studentScore < 0 || > 1000) should be

if (studentScore < 0 || studentScore > 1000)


只是解释一下Bryian'c解决方案:'||'是条件OR运算符,并且它需要两个bool值并返回一个bool结果:

Just to explain Bryian'c solution a little: '||' is the conditional OR operator, and it takes two bool values and returns a bool result:
bool result = a || b;

如果其中一个或两个操作数为true,则结果为true,否则为false:

Where the result is true if either or both operands is true and false otherwise:

result   a      b
false    false  false
true     false  true
true     true   false
true     true   true

在C#中,还定义了条件 a 将首先进行评估,如果为真,则不会对条件b进行评估(这在以后很重要)

所以当你写时如果包含OR运算符的条件,左侧和右侧必须是导致bool值的完整表达式。



还有一个AND运算符' &&'如果两个操作数都为真则返回true,否则返回false:

In C#, it is also defined that the condition a will be evaluated first, and if true, the condition b will not be evaluated at all (this is important later on)
So when you write an if condition that includes the OR operator, the left and right sides must be complete expressions which result in a bool value.

There is also an AND operator '&&' which returns true if both operands are true and false otherwise:

result   a      b
false    false  false
false    false  true
false    true   false
true     true   true

如果 a b $ c>是真的。

This also only evaluates b if a is true.


这篇关于如何修复下面的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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