-
April 19th, 2013, 04:06 PM
#1
Need Help
I am writting a C# GUI program that will calculate a car payment. I keep getting an error on one line of code. All text boxes are correctly identified in the code.
Here is the code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CarGUI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double CarPrice, Total;
double CreditScore;
double MonthlyPayment;
double InterestRate;
double PaymentPlan;
CarPrice = Convert.ToDouble(textBox1);
PaymentPlan = Convert.ToDouble(textBox3);
CreditScore = Convert.ToDouble(textBox2);
if (CreditScore <= 450)
InterestRate = .12;
else if (CreditScore >= 451 && CreditScore >= 600)
InterestRate = .10;
else if (CreditScore >= 601 && CreditScore >= 700)
InterestRate = .07;
else
InterestRate = .02;
MonthlyPayment = (CarPrice / PaymentPlan) * InterestRate;
label4.Text = String.Format ("Car Price {0}", CarPrice.ToString("C"));
label5.Text = String.Format("with a credit score of {0}", CreditScore.ToString);
label6.Text = String.Format("making your payments {0}", MonthlyPayment.ToString("C"));
}
}
}
Label5 line is the error that I get.
Thanks for looking and helping.
DK
Last edited by BioPhysEngr; April 19th, 2013 at 10:56 PM.
-
April 19th, 2013, 10:56 PM
#2
Re: Need Help
I have surrounded your code snippet with [code] and [/code] tags to preserve the indentation. Welcome to the forum!
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
-
April 19th, 2013, 10:57 PM
#3
Re: Need Help
ToString() is a method. You just need to adjust the line to:
Code:
label5.Text = String.Format("with a credit score of {0}", CreditScore.ToString());
This was a simple problem, but for more complicated problems, it's very helpful to know the specific error message. It's WAY easier to debug if the error message is known.
Hope that helps!
Last edited by BioPhysEngr; April 19th, 2013 at 10:58 PM.
Reason: oops! forgot to fix the snippet
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|