Reputation: 1
I'm new at programming. I tried to modify the code to use the Math.round method in place of the Convert.ToString and here's where things got confusing. I've researched the error but still don't quite see what to do. thanks for any help.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace InvoiceTotal
{
public partial class frmInvoiceTotal : Form
{
public frmInvoiceTotal()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void btnCalculate_Click(object sender, System.EventArgs e)
{
decimal Subtotal = Decimal.Parse(txtSubtotal.Text);
decimal discountPercent = 0m;
if (Subtotal >= 500)
{
discountPercent = .2m;
}
else if (Subtotal >= 250 && Subtotal < 500)
{
discountPercent = .15m;
}
else if (Subtotal >= 100 && Subtotal < 250)
{
discountPercent = .1m;
}
decimal discountAmount = Math.Round(discountAmount, 2);
decimal invoiceTotal = Math.Round(invoiceTotal, 2);
txtDiscountPercent.Text = discountPercent("p1");
txtDiscountAmount.Text = discountAmount("c");
txtTotal.Text = invoiceTotal.ToString("c");
txtSubtotal.Focus();
}
private void btnExit_Click_1(object sender, EventArgs e)
{
this.Close();
}
private void frmInvoiceTotal_Load(object sender, EventArgs e)
{
}
}
}
-----------------------
Error List:
Error 1 'discountPercent' is a 'variable' but is used like a 'method'
Error 1 'discountAmount' is a 'variable' but is used like a 'method'
Upvotes: 0
Views: 75
Reputation: 10738
Just as the error says, discountPercent
is a variable, not a method. You need to use the .ToString()
method on the discountPercent
variable.
txtDiscountPercent.Text = discountPercent.ToString("p1");
txtDiscountAmount.Text = discountAmount.ToString("c");
Upvotes: 2