Steve Bonoo

Steve Bonoo

  • NA
  • 10
  • 556

Radiobutton

May 3 2022 4:09 PM

Dear sir,

I made two radio buttons for converting the temperature. Radiobutton1 converts the temperature from Celsius to Fahrenheit and Radiobutton2 the other way around. But when I click on Radiobutton2, my output is always 0. What am I doing wrong?

With sincerely,

Steve

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 TemperatuurConversie
{
    public partial class frmTemperatuur : Form
    {

        public frmTemperatuur()
        {
            InitializeComponent();
        }
        double invoerGetal = 0;
        // double invoerGetal2 = 0;


        double berekenTempVanCnaarF(double invoerGetal)
        {
            double CnaarF = 0;
            CnaarF = ((9 * invoerGetal) / 5 + 32);
            return CnaarF;
        }


        double berekenTempFnaarC(double invoerGetal)
        {
           double FnaarC = 0;
           // FnaarC = double.Parse(txtInvoer.Text);
            FnaarC = ((5 / 9) * (invoerGetal - 32));
            return FnaarC;
        }

        private void btnConversie_Click(object sender, EventArgs e)
        {


            if (rdoCelsiusToFahrenheit.Checked == true)
            {
                txtResultaat.Text = (berekenTempVanCnaarF(invoerGetal).ToString());
            }

            if (rdoFahrenheitToCelsius.Checked == true)

            {

                 txtResultaat.Text = (berekenTempFnaarC(invoerGetal).ToString());
            }

        }

        private void txtInvoer_TextChanged(object sender, EventArgs e)
        {
            try
            {
                errorProvider1.SetError(txtInvoer, "");
                invoerGetal = double.Parse(txtInvoer.Text);
            }
            catch (Exception exception)
            {
                errorProvider1.SetError(txtInvoer, exception.Message);
            }

            /*     try
                 {
                     invoerGetal2 = double.Parse(txtInvoer.Text);
                 }
                 catch (Exception exception)
                 {
                     errorProvider1.SetError(txtInvoer, exception.Message);
                 } */

        }

        private void rdoCelsiusToFahrenheit_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void rdoFahrenheitToCelsius_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void txtResultaat_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnFnaarC_Click(object sender, EventArgs e)
        {

        }

    }
}

Answers (3)