Results 1 to 4 of 4

Thread: German Question

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2022
    Posts
    1

    German Question

    Hey guys, im new to Visual Studios, and as a student i had some hard times, getting started.
    Recently we had a test in shool. And my teacher rejeckted my Questions, why my sketch didnt work..
    Could you guys give me a hint?

    Its a simple code.. ive just made a button a textbox and a label box.. thats it.

    If i fill the textbox with numbers, for example 21000 It will calculate a Percentual result
    in this case we had to calculate inflation of Cucumbers lol The more you grow.. the less they'll be worth

    Code:
            private void buttoncalc_Click(object sender, EventArgs e)
            {
                double Rechner = 0;
                double Ergebnis = 0;
    
                Umsatz = Convert.ToDouble(txtRechner.Text);
                switch (Rechner)
                {
                    case var expression when Rechner <= 100001:
                        Bonus = 3.2;
                        break;
                    case var expression when Rechner <= 100000:
                        Bonus = Umsatz / 100 * 4.5;
                        break;
                    case var expression when Rechner <= 30000:
                        Bonus = Umsatz / 100 * 8.4;
                        break;
                    case var expression when Rechner <= 20000:
                        Bonus = Umsatz / 100 * 8.7;
                        break;
                    case var expression when Rechner >= 10000:
                        Bonus = Umsatz / 100 * 9;
                        break;
                }
                    lblausgabe.Text = "Das Ergebnis ist " + Environment.NewLine + Bonus.ToString("c2") + ".";
                
            }

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: German Question

    First off, this clearly isn't VB.NET code. Presumably it is C#?

    Based on the order and conditions of your case statements (the syntax of which looks very goofy to me, but I'm unfamiliar with C# for the most part, so it might be right), only the first and last case blocks can ever be entered. It is impossible for a number to exist that will cause the middle three case blocks to be entered. I'll leave it up to you to figure out why. That's as much of a hint I'm willing to give for homework.

    Edit to add: Also, as written, Rechner will always have a value of 0. Again, I'll let you work out why.

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: German Question

    Welcome to VBForums

    I have moved this thread from our VB.Net forum to our C# forum.

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: German Question

    1) Rechner is set to 0... and never changes
    2) case var expression when Rechner <= 100001: doesn't look right to me ... case when Rechner <= 100001: should be right.
    3) But Rechner is always 0, so it will always drop into that first case.
    4) Actually #2 is wrong... it should be case <= 1000001:
    5) What should happen when Rechner is less than 10000?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width