where is the problem in function?

abdullah 1 Reputation point
2022-06-02T15:00:19.363+00:00

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 WindowsFormsApp21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public double Sasd(double s,double y)
{if (radioButton1.Checked == true)
{
double e = Math.Pow(s, y)/(s*y);

            return e;




        }

        else (radioButton2.Checked == true){

            double o = s * y;

            return o;

        }






    }
    private void button1_Click(object sender, EventArgs e)
    {
        double s = Convert.ToDouble(textBox1.Text);

        double y = Convert.ToDouble(textBox2.Text);
        label3.Text = Sasd(s, y).ToString();


    }
}

}

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,219 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Kamlesh Kumar 3,861 Reputation points
    2022-06-02T16:04:29.98+00:00

    Hi @abdullah ,

    Thank you for asking this question on the Microsoft Q&A Platform.

    Seems you are missing some piece of code also check the else condition, Try to update the below code and see the result.

            public double Sasd(double s, double y)  
            {  
                if (radioButton1.Checked == true)  
                {  
                    double e = Math.Pow(s, y) / (s * y);  
                    return e;  
                }  
                else if (radioButton2.Checked == true)  
                {  
                    double o = s * y;  
                    return o;  
                }  
                else  
                {  
                    double t=0;  
                    return t;  
                }  
            }  
    

    Regards,
    Kamlesh Kumar
    BizTalk Techie

    Please don't forget to click on 205836-130616-image.png or upvote 205759-130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is How

    Want a reminder to come back and check responses? Here is how to subscribe to a Notification

    If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

    0 comments No comments

  2. Yijing Sun-MSFT 7,061 Reputation points
    2022-06-03T06:08:46.567+00:00

    Hi @abdullah ,
    First, you have wrong with if else. And then you need return the value in the Sasd method.

    private void button1_Click(object sender, EventArgs e)  
            {  
                double s = Convert.ToDouble(textBox1.Text);  
                double y = Convert.ToDouble(textBox2.Text);  
                label3.Text = Sasd(s, y).ToString();  
            }  
            public double Sasd(double s, double y)  
            {  
                double x = 0;  
                if (radioButton1.Checked == true)  
                {  
                    double e = Math.Pow(s, y) / (s * y);  
                    x= e;  
                }  
                else if (radioButton2.Checked == true){  
                    double o = s * y;  
                    x=o;  
                }  
                return x;  
            }  
    

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments