using System;
namespace Mounova
{
class Chanatza
{
static void Main()
{
int i, n, num, sum = 0, avg = 0, min, max;
Console.Write("How many number you put: ");
num = int.Parse(Console.ReadLine());
i = 1;
do
{
Console.Write("Input your values: ");
n = int.Parse(Console.ReadLine());
sum = sum + n;
avg = sum / num;
i = i + 1;
max = Math.Max(n);
min = Math.Min(n);
} while (i <= num);
Console.Write("---------------------------------------");
Console.WriteLine("Avg of number is: {0}", avg);
Console.ReadLine();
}
}
}
จาก CODE ข้างต้นมันฟ้องว่า ERROR ว่า
No overload for method 'Min' takes 1 arguments
No overload for method 'Max' takes 1 arguments
มันคือไรเหรอครับ
ลองแก้เป็นแบบนี้แต่ผลลัพธ์ไม่ได้ Min กับ Max MAX กับ MIN จะได้ 2 ตัวท้ายที่ผมป้อน
Code (C#)
using System;
namespace Mounova
{
class Chanatza
{
static void Main()
{
int i, n, num, sum = 0, avg = 0, min, max;
Console.Write("How many number you put: ");
num = int.Parse(Console.ReadLine());
i = 1;
do
{
Console.Write("Input your values: ");
n = int.Parse(Console.ReadLine());
sum = sum + n;
avg = sum / num;
min = Math.Min(n, n);
max = Math.Max(n, n);
i = i + 1;
} while (i <= num);
Console.WriteLine("---------------------------------------");
Console.WriteLine("Avg of number is: {0}", avg);
Console.WriteLine("Min of your number to input is: {0}", min);
Console.WriteLine("Max of your number to input is: {0}", max);
Console.ReadLine();
}
}
}
using System;
namespace Mounova
{
class Chanatza
{
static void Main()
{
double i, n, num, sum = 0, avg = 0, min, max;
Console.Write("How many number you put: ");
num = double.Parse(Console.ReadLine());
i = 1;
do
{
Console.Write("Input your values: ");
n = double.Parse(Console.ReadLine());
sum = sum + n;
avg = sum / num;
min = Math.Min(n, n);
max = Math.Max(n, n);
i = i + 1;
} while (i <= num);
Console.WriteLine("---------------------------------------");
Console.WriteLine("Avg of number is: {0}", avg);
Console.WriteLine("Min of your number to input is: {0}", min);
Console.WriteLine("Max of your number to input is: {0}", max);
Console.ReadLine();
}
}
}
แน่นอนอยู่แล้วครับ ก็เอาค่า (n,n) ก็ได้ค่าที่ป้อนล่าสุด แต่ผมจำsintax ไม่ได้ละ เคยทำนานแล้ว
ใช้ if เอาละกัน
min ทำเอาเองนะครับ
Code (C#)
using System;
namespace Mounova
{
class Chanatza
{
static void Main()
{
double i, n, num, sum = 0;
double avg = 0;
double min = 0;
double max = 0;
Console.Write("How many number you put: ");
num = double.Parse(Console.ReadLine());
i = 1;
do
{
Console.Write("Input your values: ");
n = double.Parse(Console.ReadLine());
sum = sum + n;
avg = sum / num;
if(max < n){
max = n;
}
i = i + 1;
} while (i <= num);
Console.WriteLine("---------------------------------------");
Console.WriteLine("Avg of number is: {0}", avg);
Console.WriteLine("Min of your number to input is: {0}", min);
Console.WriteLine("Max of your number to input is: {0}", max);
Console.ReadLine();
}
}
}