-
May 9th, 2022, 12:04 PM
#1
Thread Starter
New Member
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") + ".";
}
-
May 9th, 2022, 02:02 PM
#2
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.
-
May 9th, 2022, 02:09 PM
#3
Re: German Question
Welcome to VBForums
I have moved this thread from our VB.Net forum to our C# forum.
-
May 9th, 2022, 03:03 PM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|