boomoto

Ok i'm still learning c# i'm doing a project for school and i'm tryign to create a basic program where it calculates the shippign cost based on weight, The problem i'm having is i can;t mutiply my final answer by 0.12 it gives me

Error 1 Operator '*' cannot be applied to operands of type 'decimal' and 'double'

now my code is this

private void Btn_Calculate_Click(object sender, EventArgs e)

{

//Calculate Shipping cost

decimal poundDecimal, costDecimal, ouncesDecimal, cost1Decimal;

try

{

//convert input values to numeric and assign to variables.

poundDecimal = decimal.Parse(txt_pound.Text);

ouncesDecimal = decimal.Parse(txt_ounces.Text);

//costDecimal = decimal.Parse(txt_cost.Text);

try

{

ouncesDecimal = decimal.Parse(txt_ounces.Text);

//Calculate values.

costDecimal = (poundDecimal * 16 + ouncesDecimal)*0.12;

//display

lsb_cost.Items.Add(costDecimal.ToString("C"));

}

catch

{

//invalid number

MessageBox.Show("Data Error");

}

}

catch

{

//invalid number

MessageBox.Show("Data Error press OK to try again");

}

}

so that 0.12 is not working i need to mutiply that by 0.12 please help me



Re: Visual C# General Basic equation

JohnWein

Cast them one way or the other so you can multiply.





Re: Visual C# General Basic equation

boomoto

ya i figured that out or i found a loop whole where 0.12 = 12/100 so that worked for me thanks though