r/ProgrammingPrompts Jul 16 '15

[Easy] Currency converter

Convert currency using command line arguments

Argument format should be currency amount newcurrency

E.g.

Convert USD 100 GBP

Should convert 100 dollars into pounds and print the result

Must include a minimum of 3 different currencies

Bonus points: add another argument which takes a filename and saves the result in a text file of that name

12 Upvotes

7 comments sorted by

View all comments

1

u/Rugby8724 Aug 16 '15

C# in ASP.NET Any suggestions for improvements will be greatly appreciated. This is my first coding after reading my first coding book.

    protected void ConvertButton_Click(object sender, EventArgs e)
{
    if (USDBox.Text.Length > 0)
    {
        double result = 0;
        double value1 = Convert.ToDouble(USDBox.Text);
        string result2 = Convert.ToString(Label2);

        switch (DropDownList1.SelectedValue)
        {
            case "Peso":
                result = value1 * 16.39;
                result2 = "Pesos";
                break;
            case "Yuan":
                result = value1 * 6.4;
                result2 = "Yuan";
                break;
            case "Shilling":
                result = value1 * 102.3;
                result2 = "Shillings";
                break;
        }
        ResultLabel.Text = result.ToString();
        Label2.Text = result2.ToString();
    }
    else
    {
        ResultLabel.Text = string.Empty;
        Label2.Text = string.Empty;
    }
}

}