mardi 9 juin 2020

I'm using a series of if/else statements, but instead of letting me "go through" them when I run, it goes straight to the last else statement

(beginner here using c# on visual studio who's testing out if/else statements) I have two windows open in Visual studio, one where I create the classes I need:

{
       public string firstName { get; set; }
       public string lastName { get; set; }

        public string fullName
        {
            get
            {
                return firstName + lastName;
            }
        }


    }

and one with all my if/else statements:

{
            Person person = new Person();
            person.firstName = "John";
            person.lastName = "Doe";
            if (person.fullName == "John Doe")
            {
                Console.WriteLine("Welp... you've passed... you want another test?");
                string x = Console.ReadLine();
                if (x == "Yes")
                {
                    Console.WriteLine("Alright... what's 1+1?");
                    string y = Console.ReadLine();
                    if (y == "2")
                    {
                        Console.WriteLine("Yay! You're right!");
                    }
                    else
                    {
                        Console.WriteLine("oop... that's wrong my dude");
                    }

                }
                 else 
                {
                    Console.WriteLine("Lame... guess  that's bye for now.");
                }

            }
            else
            {
                Console.WriteLine("oop... ya didn't pass. guess that's bye for now.");
            }

        }

When I run this, instead of letting me go through all the if/else statements, it brings me straight to the last else statement, and prints oop... ya didn't pass. guess that's bye for now. Sorry about the length, and anything that was confusing (I'm still working on my vocabulary haha) Thanks for taking the time for a beginner.

Aucun commentaire:

Enregistrer un commentaire