Currency Converter Program in C#

Problem:

Create a program in C# that will ask the user to enter a value in dollar and the program has an option for the user to select whether to convert the dollar into peso, rupee or euro.

Kindly follow the simple steps in creating this project.

  1. Open your Visual Studio 2010 or higher version.
  2. Create a new project.
  3. Select Visual C#, and choose Windows Form Application.
  4. This is our sample form design.
    c#currency1
  5. The coding starts now, double click the first radio button (to Philippine Peso) and paste the code below.
if (radioButton1.Checked == true)
{
label2.Text = "enter peso to dollar value";
textBox2.Focus();
}

The code above must be inserted on the CheckedChanged event of the radio button.

Example:

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
//paste code here
}
  1. Next is the second radio button (to Euro), double click the control and paste the code.
if (radioButton2.Checked == true)
{
label2.Text = "enter euro to dollar value";
textBox2.Focus();
}
  1. Let’s proceed to the third radio button (to Rupee). Double click and paste the code below.
if (radioButton3.Checked == true)
{
label2.Text = "enter rupee to dollar value";
textBox2.Focus();
}
  1. Double click convert button and paste the code below.
if (radioButton1.Checked == true)
{
MessageBox.Show("PHP: " + (double.Parse(textBox1.Text) * double.Parse(textBox2.Text)));
}
else if (radioButton2.Checked == true)
{
MessageBox.Show("Euro: " + (double.Parse(textBox1.Text) * double.Parse(textBox2.Text)));
}
else if (radioButton3.Checked == true)
{
MessageBox.Show("Rupee: " + (double.Parse(textBox1.Text) * double.Parse(textBox2.Text)));
}

Code Explanation:

Using the if else if statement in c#, the code will checked which radio button has been selected, then the program will display the message stating the value of the dollar when converted to a specific currency.

c#currency2

  1. Feel free to revise the code, you can add other currency if you want.
  2. If you’re done, save the project and test the program, press F5.

Download

, , , , ,

Post navigation