【发布时间】:2016-03-08 03:06:09
【问题描述】:
我正在尝试开发一个程序来计算用户输入的分数。我还试图对用户输入的高低设置一个限制(即 0 = 100)。但是当我使用十进制时,它一直给我这个错误,“运算符'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Grade_Program
{
class Program
{
static void Main(string[] args)
{
string First;
string Last;
First = "Cristiano";
Last = " Ronaldo";
Console.Write("Please enter student name <First Last>: ");
Console.WriteLine(First + Last );
Console.WriteLine(" ");
Console.WriteLine("*************NOTE**********************************************");
Console.WriteLine("*** Be sure to include decimal point for scores. ***");
Console.WriteLine("*** !!!All score should range from 0.00 to 100.00 !! ***");
Console.WriteLine("*** ***");
Console.WriteLine("*** For example : 80.50 ***");
Console.WriteLine("***************************************************************");
Console.WriteLine(" ");
decimal Exam_1;
decimal Exam_2;
decimal Exam_3;
decimal Assignment_1;
decimal Assignment_2;
Console.Write("Please enter score for Exam 1 <Example: 100.0>: ");
Exam_1 = Convert.ToDecimal(Console.ReadLine());
if (Exam_1 < 0.0 | Exam_1 > 100.0)
Console.Write("Exam score cannot be less than 0. or greater than 100.0. Please re-enter the score for Exam 1 <Example: 95.0>:");
Exam_1 = Convert.ToDecimal(Console.ReadLine());
Console.Write("Please enter score for Exam 2 <Example: 0.0>: ");
Exam_2 = Convert.ToDecimal(Console.ReadLine());
【问题讨论】:
-
试试
0M <= myDecimal || 100M >= myDecimal(参考:msdn.microsoft.com/en-us/library/364x0z75.aspx) -
大多数情况下,这个错误是因为投射问题。如果您粘贴代码,我们可以准确给出正确答案。
标签: c# .net comparison