10 Replies - 1299 Views - Last Post: 30 July 2013 - 02:52 PM Rate Topic: ***** 1 Votes

#1 Nogard Htrae  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 04-November 11

Radiobutton project that doesnt use (if, else if) statement

Posted 04 November 2011 - 07:06 PM

Hello everyone. As the title suggest I have a bit of a problem with a current project which happens to use RadioButtons. Being a bit lost I have come to dream in code for help.

My current issues is writing the project without using (if else) statement. Let me just link this
( http://www.genghiskh...Assign03_.htm). That would be the link to the project I am working on. I made a working version of it using (if else) statements. However the projects specifies that we are not allowed to use (if else) when making the project. This is where I am lost I don't know of any other way to make the project other than using (if else) statement. At the moment I am having a bit of trouble wording my question. So if my question seems vague I do apologize. Any help would be appreciated. Thanks in advance.


-Nogard

Is This A Good Question/Topic? 0
  • +

Replies To: Radiobutton project that doesnt use (if, else if) statement

#2 tsackey  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 48
  • Joined: 11-March 10

Re: Radiobutton project that doesnt use (if, else if) statement

Posted 04 November 2011 - 08:31 PM

Your link doesn't work

This post has been edited by tlhIn`toq: 05 November 2011 - 06:33 AM
Reason for edit:: No need to quote the entire immediately preceding post

Was This Post Helpful? 0
  • +
  • -

#3 Nogard Htrae  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 04-November 11

Re: Radiobutton project that doesnt use (if, else if) statement

Posted 04 November 2011 - 08:48 PM

Sorry about that should have checked. The website for some reason doesn't work if it is through a link. Lets try this
(/http://www.genghiskhent.com/devvie/895/Assignments/895Assign03_.htm\). Only works if the link is copied pasted.


-Nogard
Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Radiobutton project that doesnt use (if, else if) statement

Posted 04 November 2011 - 09:08 PM

I'm sorry, but we won't do homework assignments for you. We ask that you show YOUR effort. Post what you have tried here. Don't link to another site.
Was This Post Helpful? 0
  • +
  • -

#5 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4188
  • View blog
  • Posts: 11,857
  • Joined: 18-April 07

Re: Radiobutton project that doesnt use (if, else if) statement

Posted 04 November 2011 - 10:36 PM

The instructions in part one tell you how you can do this without an if-else statement. You have two options...

"use either (1) a foreach loop or (2) a general RadioButton click event handler that is wired to each RadioButton in the group."

Another line to pay attention to is right before this line and reads "See if you can use one of the methods shown in class to determine which RadioButton was selected"

So you covered a method in class that you use to determine which radio button was selected.

As for the wiring approach, think of one function which will take a sender object and an eventargs parameter, then in each click event of the radio buttons it passes the parameters to this function.

:)
Was This Post Helpful? 2
  • +
  • -

#6 Nogard Htrae  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 04-November 11

Re: Radiobutton project that doesnt use (if, else if) statement

Posted 04 November 2011 - 10:38 PM

I was not asking for a solution just would like to know a different way of using radio buttons without (if, else if) a simple code snippet would suffice.
if (radJPY.Checked )
                {
                    convertedAmmount = dollars * JPY;
                    lblConvertedAmount.Text = convertedAmmount.ToString() + "Yen(s)";
                }
else if (radEUR.Checked)
                {
                    convertedAmmount = dollars * EUR;
                    lblConvertedAmount.Text = convertedAmmount.ToString() + "Euro(s)";
                }


A piece of my code that I used. As I stated before I completed the program and it does work as intended. However when programing I did not follow the assignment specifications. I used (if, else if) statements for the radio buttons which I am not allowed to.
Was This Post Helpful? 0
  • +
  • -

#7 Nogard Htrae  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 04-November 11

Re: Radiobutton project that doesnt use (if, else if) statement

Posted 04 November 2011 - 11:07 PM

I guess that class I missed comes back to haunt me :). Though I did read the entire assignment and did try with a foreach loop. However when programing I realized I had no idea how to take the users radio button input without assigning the radio buttons a constant variable. Perhaps I might be over thinking the program and making it unnecessarily difficult. This is as far as I got on the click event handler. Which doesnt work for some reason it says " convertedAmt = dollars * Eur;" that dollars is unassigned local variable.
  
private void radEUR_Checked(object sender, EventArgs e)
{
            decimal dollars;
            const decimal Eur = 0.65m; 
            decimal convertedAmt;
            convertedAmt = dollars * Eur;
            lblConvertedAmount.Text = convertedAmt.ToString();
}


Thanks for the reply.


-Nogard



View PostMartyr2, on 04 November 2011 - 10:36 PM, said:

The instructions in part one tell you how you can do this without an if-else statement. You have two options...

"use either (1) a foreach loop or (2) a general RadioButton click event handler that is wired to each RadioButton in the group."

Another line to pay attention to is right before this line and reads "See if you can use one of the methods shown in class to determine which RadioButton was selected"

So you covered a method in class that you use to determine which radio button was selected.

As for the wiring approach, think of one function which will take a sender object and an eventargs parameter, then in each click event of the radio buttons it passes the parameters to this function.

:)

Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,358
  • Joined: 02-June 10

Re: Radiobutton project that doesnt use (if, else if) statement

Posted 05 November 2011 - 06:36 AM

<cough> switch <cough>
Was This Post Helpful? 2
  • +
  • -

#9 Nogard Htrae  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 04-November 11

Re: Radiobutton project that doesnt use (if, else if) statement

Posted 05 November 2011 - 07:59 PM

Thanks for the help folks. I got it to work ecept one problem when adding the input validation I get "not all code paths return a value" error on my set inputs.

private bool SetInputs(ref String strCurrency, ref Double dollars)
        {
            
            bool isValidVal;
            isValidVal = Double.TryParse(txtValue.Text, out dollars) && dollars >= 0;

            if (!isValidVal)
            {
                MessageBox.Show("Input must be a nonnegative number",
                    "Invalid Input", MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
                txtValue.Focus();
                txtValue.SelectAll();
            }
            else
            foreach (RadioButton rdo in grpBtn.Controls)
            {
                if (rdo.Checked)
                {
                    strCurrency = rdo.Text;
                    break;
                }
            }
        }

Was This Post Helpful? 0
  • +
  • -

#10 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4312
  • View blog
  • Posts: 7,467
  • Joined: 08-June 10

Re: Radiobutton project that doesnt use (if, else if) statement

Posted 06 November 2011 - 12:42 AM

It's because no paths return a value. Your method claims it returns a bool, yet you never return anything at all. If you don't want it to return anything, use void. Otherwise, return a valid value along every possible exit point (or make the method have only one exit point).
Was This Post Helpful? 0
  • +
  • -

#11 kwontum  Icon User is offline

  • New D.I.C Head

Reputation: -20
  • View blog
  • Posts: 19
  • Joined: 24-July 13

Re: Radiobutton project that doesnt use (if, else if) statement

Posted 30 July 2013 - 02:52 PM

View PostNogard Htrae, on 04 November 2011 - 07:06 PM, said:

Hello everyone. As the title suggest I have a bit of a problem with a current project which happens to use RadioButtons. Being a bit lost I have come to dream in code for help.

My current issues is writing the project without using (if else) statement. Let me just link this
( http://www.genghiskh...Assign03_.htm). That would be the link to the project I am working on. I made a working version of it using (if else) statements. However the projects specifies that we are not allowed to use (if else) when making the project. This is where I am lost I don't know of any other way to make the project other than using (if else) statement. At the moment I am having a bit of trouble wording my question. So if my question seems vague I do apologize. Any help would be appreciated. Thanks in advance.


-Nogard

maybe try Switch/case ???
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1