How to check user input with if else

atw311atw311 Member ✭✭

Hey guys, I'm very new to all this and am just trying to learn a bit. I'm trying to make a simple app and i can't figure out how to take the info a user puts in my input box and check it to display different thing based on what they put. It's a simple app for finding your out in a dart game. I have the input box and if the user types "180" i want it to redirect to an image i made showing what to aim for. if they type 150, it would redirect to a different image. and so on. I figured it would be a simple "if(var userInput = "180")" then do x, else... But apparently I'm a super noob haha. I'm having a heck of a time expressing this question in google searches to figure out what to study lol. any help would be appreciated, thanks all.

Answers

  • atw311atw311 Member ✭✭

    Ok, I think i figured a way to do it, but I will be having around 160 if statements.. Seems like over complicated code.. but this is what ive got so far.
    public MainPage()

        {
            InitializeComponent();
        }
    
        async void ButtonClicked(object sender, EventArgs e)
        {
            string goOut = Out.Text;
                if (goOut == "180")
            {
                ShowAlert("180", "Your Out Is: T20, T20, T20");
    
            }
                else
            {
                ShowAlert("nope","No out");
            }
    
    
    
        }
        void ShowAlert (string title, string message)
        {
            DisplayAlert(title, message, "Return");
        }
    }
    

    }

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Welcome to programming.
    There are certainly a lot better strategies. I suspect that architecting a program is maybe a little new to you. Most people start out with basic learning tutorials. Then maybe small projects. And work their way up.

    And generally you start out as a 'coder' taking the assignments handed to you by the 'architect'. In that way you see how others take on a problem and see the approaches more experienced people use. The problem I'm seeing here is that you're trying to be the architect while you're still learning the basics. Its like trying to be the guy designing the house, while you're still learning how the circular saw works.

    One approach is to name your images in a way to matches the expected input. If they type 150 show image 150.jpg. Or if they are ranges then anything between 150-159 gets the 150.jpg image

    Another approach is a key,value pair list of inputs and file names.

    There's lots of ways to handle something like beyond the first-semester if-else. In this case learning and experience will come as you move from small projects to medium to large.

  • atw311atw311 Member ✭✭

    Thanks for the reply. Yea i tried like a codecadamy C# class that was 6 hours, literally learned nothing lol. Tried a 30 hour microsoft class, and switched to some more xamarin specific courses but the 2 problems i have are, 1) seems like xamarin gets updated often or just had a big one, and a lot of the tutorials use "obsolete" code. and 2) I have trouble learning actual uses for the turorial stuff, it feels like im basically just copy and pasting. Any pro tips on better resources or more updated info?
    What you said about the coder and the architect thing makes a lot of sense though, i never really thought of it as 2 seperate roles before. Thanks again for the help.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Addressing items:
    1. Don't worry about updates. Rarely does something get removed from coding languages like C#. C# evolves from version 3, to 4 to 5, ...7 Those evolutions are additions. New things. Yes Xamarin is growing quickly. Like a child having a growth spurt. So? You're at a point where you learning the ultra basics of C# and coding in general. How to think like a developer. Concept stuff, not stuff that will be affected by the nitty-gritty of changes between January and May releases.
    2. "I have trouble learning from classes" - Sorry for how this sounds but... I've heard that [email protected] from people for the last 15+ years of mentoring and I simply don't buy it except for the 2% that are diagnosed with actual learning deficits or reading issues like dyslexia. The other 98% I personally feel are today's kids that expect to take a 6 hour course and know all there is to. Or to watch one YouTube video and expect to be a senior developer. Nobody wants to accept that career-grade skills will require career-grade investment in their education. That means actually enrolling in an institute of higher learning and taking a real course for a couple years as a start. Then on top of that one has to be devouring every "Learn C# in 60 days" book... and all the videos available... etc. etc. The faster you want to be proficient the more you have to invest.

    Let's put it in this analogy... If you wanted to have enough proficiency in Russian to be a paid translator and the U.N. how much learning, practice and investment would you have to commit to? Well here you have to learn at least 2 languages, more like 3: C#, XAML, JSON... Then on top of that you have to learn coding paradigms... strategies... design patterns... Its like not only learning Russian, but then learning the entire Russian culture, gov't structure, insurance programs, rules of the road, and building codes so you can be an electrician there.

    So my pro tip is: Turn off your TV cable... quick checking in on facebook... stop going out on Friday nights... Stop doing anything and everything that distracts you from only only job in life as a student: Learning. That's its. That's your life right now: Learning. For the next year.

Sign In or Register to comment.