2
Answers

comboBox select form

Ask a question
mileswoolgar

mileswoolgar

18y
1.9k
1

Hi

As a newbie I'm trying to learn to use methods... and I'm a bit stuck .  This is what I'm trying to achieve [I'm expanding an exercise from the internet]:

1. select one of 3 countries from a comboBox [cboCountry] - show selected country in cboCountry

2. enter amount of cash to do calculation on [txtAmount]

3. depending on which country is selected will depend on the FxRate - which will show in the textBox txtFxRate

4. txtSubTotal (taxableAmount) should show figure entered in txtAmount * figure entered in txtFxRate [as passed by the cboCountry]

5. txtCashierFee should show 2% on the subTotal [cashierFee of 2% on the taxableAmount]

6. txtGrandTotal then shows subTotal + cashierFee
 

These are the two errors I get:

C:\BEGIN2\code\Lesson4x\ForEx\Form1.cs(265): 'displayResult' denotes a 'variable' where a 'method' was expected

C:\BEGIN2\code\Lesson4x\ForEx\Form1.cs(236): The name 'fxRate' does not exist in the class or namespace 'ForEx.Form1'

Many thanks for your help in advance

My code:

 

private void btnDollar_Click(object sender, System.EventArgs e)

{

#region select

switch(cboCountry.Text)

{

case "USA":

{

fxRate = 1.74743;

break;

}

case "PHIL":

{

fxRate = 89.4507;

break;

}

case "SAU":

{

fxRate = 6.55381;

break;

}

}

#endregion

double fxRate;

double taxableAmount; //subtotal

double cashierFee; // 2%

double grandTotal;

double displayResult;

txtFxRate.Text = cboCountry.Text.ToString();

txtTaxableAmount.Text = taxableAmount.ToString();

taxableAmount = calculateTaxableAmount(taxableAmount, fxRate);

cashierFee = calculateCashierFee(taxableAmount);

grandTotal = calculateGrandTotal(taxableAmount, cashierFee);

displayResult = displayResult(grandTotal);

}

#region private methods

private double calculateTaxableAmount(double taxableAmount, double fxRate)

{

return taxableAmount * fxRate;

}

private double calculateCashierFee(double taxableAmount)

{

return taxableAmount * 0.02;

}

private double calculateGrandTotal( double taxableAmount, double cashierFee)

{

return taxableAmount + cashierFee;

}

private void displayResult(double grandTotal)

{

MessageBox.Show("grand total = " + String.Format("0.C)", grandTotal));

}

#endregion


Answers (2)