Tôi đang cố gắng tìm ra một chương trình tính toán điểm được đưa ra từ đầu vào của người dùng. Tôi cũng đang cố đặt giới hạn về mức độ đầu vào của người dùng cao hay thấp (ví dụ: 0 < = hoặc> = 100). Nhưng khi tôi sử dụng số thập phân nó giữ cho tôi lỗi này, "điều hành '<' không thể được áp dụng cho toán hạng của loại 'thập phân' và 'đôi'"Toán tử '<' không thể áp dụng cho các toán hạng kiểu 'thập phân' và '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());
Xin vui lòng gửi chính xác dòng mã đó là ném lỗi. –
Thử '0M <= myDecimal || 100M> = myDecimal' (ref: https://msdn.microsoft.com/en-us/library/364x0z75.aspx) – souldzin
Hầu hết thời gian lỗi này xảy ra do sự cố truyền. Nếu bạn dán mã, chúng tôi có thể đưa ra câu trả lời chính xác. – Sasa1234