The call is ambiguous between the following methods or properties

Hey, i'm very new to C# and im getting this error "The call is ambiguous between the following methods or properties"
5 Replies
j o s h u a
this is the code
using System;
using System.Collections.Generic;
using System.Linq;

public class Test
{
public static void Main()
{
int[] input = {16,1,2,0,4,2,7,1,2,14};

int avg = (int)Math.Ceiling(input.Sum() / input.Length);
int min_pos = 2147483647;

for (int i = input.Min(); i <= avg; i++)
{
int pos = 0;

foreach (int num in input)
{
pos += Math.Abs(num - i);
}

min_pos = Math.Min(min_pos, pos);
}

int result = min_pos;
Console.WriteLine(result);
}
}
using System;
using System.Collections.Generic;
using System.Linq;

public class Test
{
public static void Main()
{
int[] input = {16,1,2,0,4,2,7,1,2,14};

int avg = (int)Math.Ceiling(input.Sum() / input.Length);
int min_pos = 2147483647;

for (int i = input.Min(); i <= avg; i++)
{
int pos = 0;

foreach (int num in input)
{
pos += Math.Abs(num - i);
}

min_pos = Math.Min(min_pos, pos);
}

int result = min_pos;
Console.WriteLine(result);
}
}
canton7
canton73y ago
What's the full error message? You've just shown the first bit.
j o s h u a
/tmp/PKtP038Ijk.cs(11,23): error CS0121: The call is ambiguous between the following methods or properties: 'Math.Ceiling(decimal)' and 'Math.Ceiling(double)'
/tmp/PKtP038Ijk.cs(11,23): error CS0121: The call is ambiguous between the following methods or properties: 'Math.Ceiling(decimal)' and 'Math.Ceiling(double)'
canton7
canton73y ago
I'm guessing you probably wanted to do a floating-point division there? You're currently dividing an int by an int, which gives you an int. Calling Ceiling on an int doesn't make any sense (int)Math.Ceiling((double)input.Sum() / input.Length)
j o s h u a
oh yeah that was it! thanks a lot
Want results from more Discord servers?
Add your server