我正試圖想出一個程序來計算用戶輸入的等級。我也試圖限制用戶輸入的高低(即0 < =或> = 100)。但是,當我使用十進制它不斷給我這個錯誤,「操作員‘<’不能應用於類型‘十進制’和‘雙師型’的操作數」運算符'<'不能應用於'decimal'和'double'類型的操作數
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'(參照https://msdn.microsoft.com/en-us/library/364x0z75.aspx) – souldzin
多數此錯誤出現,因爲鑄造問題的時間。如果你粘貼代碼,我們可以準確地給出正確的答案。 – Sasa1234