private void btnMiles_Click(object sender, EventArgs e)
{
try
{
int milesless200 = int.Parse(txtMiles.Text);
int milesmore200 = int.Parse(txtMiles200.Text);
MilesCal workingoutmilescost = new MilesCal();
if (milesless200 > 200)
{
lblMilesMorethan200.Text = "You can't enter more then 200 in the first box";
}
else
{
if (milesmore200 == 0)
{
int carry = workingoutmilescost.MilesRepay(milesless200);
lblMilesShow.Text = carry.ToString();
}
else
{
int carry = workingoutmilescost.MilesRepay(milesless200, milesmore200);
lblMilesShow.Text = carry.ToString();
}
}
lblMilesError.Text = "No Error";
}
catch (FormatException fEx)
{
lblMilesError.Text = fEx.Message;
}
}
My Defined class of MilesCal
class MilesCal
{
public int MilesRepay(int a)
{
int x;
return x = (a*5)/100;
}
public int MilesRepay(int a, int b)
{
int y;
return y = (a*5)/100 + (b*2)/100;
}
}
This code is suppose to display in a label the cost a driver gets back from their driving at 5p for the first 200 miles then 2p after that. I have got the code working but then discovered that it has to be done using Method overflow. at the minute am getting an error Error 1 Cannot convert method group 'ToString' to non-delegate type 'string'. Did you intend to invoke the method? at
lblMilesShow.Text = carry.ToString;
Added the ().
Now the catch seems to be trippping, can i ask you guys again to work this out because its probably a simple fix again?