Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Use of unassigned local variable

$
0
0

I'm an extreme noob with C# - as in I took a tutorial yesterday and today I'm writing my first program. Not surprisingly I'm running into a problem.  The issue is "use of unassigned local variable" and it's happening for the variables Question1 through Question5. The program consists of five questions and the user will select one of three possible answers for each. I've assigned a number value to each radio button and when they click the Submit button, I add those values together and assign them to varResults. Based on the value of varResults, a messagebox is shown telling you which Walking Dead character you are most like.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace WalkingDeadQuiz

{

    publicpartial classForm1 : Form

    {

       public Form1()

       {

           InitializeComponent();

       }

       privatevoid button1_Click(object sender,EventArgs e)

       {

           int Question1;

           int Question2;

           int Question3;

           int Question4;

           int Question5;

           int varResults;

           

           if (radioButton1.Checked)

           {

               

               Question1 = 1;

               

           }

           elseif (radioButton2.Checked)

           {

           

               Question1 = 2;

           }

           elseif (radioButton3.Checked)

           {

           

               Question1 = 3;

           }

           if (radioButton4.Checked)

           {

           

               Question2 = 1;

           }

           elseif (radioButton5.Checked)

           {

              

               Question2 = 2;

           }

           elseif (radioButton6.Checked)

           {

               

               Question2 = 3;

           }

           if (radioButton7.Checked)

           {

               

               Question3 = 1;

           }

           elseif (radioButton8.Checked)

           {

               

               Question3 = 2;

           }

           elseif (radioButton9.Checked)

           {

               

               Question3 = 3;

           }

           if (radioButton10.Checked)

           {

              

               Question4 = 1;

           }

           elseif (radioButton11.Checked)

           {

               

               Question4 = 2;

           }

           elseif (radioButton12.Checked)

           {

               

               Question4 = 3;

           }

           if (radioButton13.Checked)

           {

               

               Question5 = 1;

           }

           elseif (radioButton14.Checked)

           {

               

               Question5 = 2;

           }

           elseif (radioButton15.Checked)

           {

              

               Question5 = 3;

               

           }

           varResults = Question1 + Question2 + Question3 + Question4 + Question5; 

           if (varResults == 5)

               MessageBox.Show("You are most like Zombie #12: On TV as in life, you're a bit player and you get lost in a crowd of one.");

           elseif (varResults == 6)

               MessageBox.Show("You are most like Rick: Emo much?  Seriously, you need to lighten up! People follow your lead but they're groaning inside.  And you're a little bit cuckoo. I suggest Lithium.");

           elseif (varResults == 7)

               MessageBox.Show("You are most like Lori: Your theme song is \"Torn Between Two Lovers.\"  You want it all except when it comes to food.  You need to eat a sammich, girl! And roll down your damned pants!  No one likes you and we're all glad you died.");

           elseif (varResults == 8)

               MessageBox.Show("You are most like Andrea: You're a rebel with low self-esteem.  Maybe you're a rebel BECAUSE you have low self-esteem. Frankly, no one cares why.  No one listens to you unless you fart.");

           elseif (varResults == 9)

               MessageBox.Show("You are most like Carl: Most people find you annoying and try to avoid your company.  You're handy at reaching things on the bottom shelf because you're short, but that's pretty much the extent of your usefulness. People call you an ankle-biter behind your back.");

           elseif (varResults == 10)

               MessageBox.Show("You are most like Daryl: You're kind of smelly and sweaty and people are usually repulsed by you at first meeting, but you are actually like whatever they call those ugly rocks that have pretty crystals inside.");

           elseif (varResults == 11)

               MessageBox.Show("You are most like Carol: You're too often overlooked unless it concerns girl-stuff, but you're willing and able to step up to the plate….and wash it.");

           elseif (varResults == 12)

               MessageBox.Show("You are most like Maggie: In any crowd, you're usually considered the prettiest (even if only due to lack of competition), but you're not just another pretty face. You're good at kicking butt too.  You suck.");

           elseif (varResults == 13)

               MessageBox.Show("You are most like Beth: When your name is mentioned, it most often prompts the question \"Who?\" You may be blonde but you're not having more fun.  There's really not much more to say about you.");

           elseif (varResults == 14)

               MessageBox.Show("You are most like Michonne: You one bad-ass girl.  You don't take any crap, preferring to lop off heads when anyone opposes you. Brava!");

           elseif (varResults == 15)

               MessageBox.Show("You are most like The Governor: I don't even know what to say about YOU!  Naughty!");

         

           

       }

    }

}


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>