Tôi có chương trình này lấy 3 điểm trong số 200 điểm có thể, mỗi trường được cho là đạt điểm trung bình và hiển thị phần trăm. nhưng khi tôi nhập số tôi nhận được 00.0 như một câu trả lời. Tôi có thể làm gì sai?Vấn đề toán đơn giản trong C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int Score1;
int Score2;
int Score3;
Console.Write("Enter your score (out of 200 possible) on the first test: ");
Score1 = int.Parse(Console.ReadLine());
Console.Write("Enter your score (out of 200 possible) on the second test: ");
Score2 = int.Parse(Console.ReadLine());
Console.Write("Enter your score (out of 200 possible on the third test: ");
Score3 = int.Parse(Console.ReadLine());
Console.WriteLine("\n");
float percent = ((Score1+ Score2+ Score3)/600);
Console.WriteLine("Your percentage to date is: {0:00.0}", percent);
Console.ReadLine();
}
}
}
Woot? Làm thế nào bạn có thể gõ rằng trong vòng chưa đầy 33 giây? :-P – Patrick
@Patrick: Dòng đầu tiên từ đây: http://meta.stackexchange.com/questions/9134/jon-skeet-facts/9135#9135;) – Bobby
Tôi đoán đây là một trong những cạm bẫy commen nhất của C cú pháp biểu thức của ngôn ngữ được kích hoạt ... – sum1stolemyname