C
C#7mo ago
J.user

✅ The code doesnt work as intended

The user is suppoed to write how many points(poäng) the user have, for example 100 points, and the program will then show that the user got the grade A. 100 points = grade A But the program gives you the grade F whatever the input is, I have googled and checked fullstack
23 Replies
Angius
Angius7mo ago
Try debugging this code $debug
MODiX
MODiX7mo ago
Tutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
Angius
Angius7mo ago
It will let you see what variable has what value at which point At a glance, though, the poang array doesn't ever seem to have any values added to it LasPoang returns an array of numbers, yes But you do nothing with it I assume you want that to become your new poang array
J.user
J.userOP7mo ago
Im not quite sure what you mean 😢
Angius
Angius7mo ago
static int[] LäsPoäng(string[] ämnen) LasPoang returns an array LäsPoäng(ämnen); // But you never do anything with it So your poang array remains empty
J.user
J.userOP7mo ago
How do i bridge them together if I may ask? Im doing this as an exercise from a book to learn But its very poor instructions… like it doesnt mention how to do this part
Angius
Angius7mo ago
How do you get a value from a method? Say, from Console.ReadLine()? If you wanted to print to the console the exact thing the user typed in, how would you do that? Console.ReadLine() returns a string?
J.user
J.userOP7mo ago
You call it in the main code?
Angius
Angius7mo ago
No description
Angius
Angius7mo ago
You have it right in your code Console.ReadLine() returns a value You save it in a Gitliga_poang variable And use it later Similarly, you can save the value returned from LasPoang() in a variable And use it in Omvandla()
J.user
J.userOP7mo ago
Trying to understand and do this😅 Thank you btw for taking your time and looking over my bad code
Angius
Angius7mo ago
// the method returns a value, we save it in a variable
string? text = Console.ReadLine();
Console.ReadLine(text); // we use this value later
// the method returns a value, we save it in a variable
string? text = Console.ReadLine();
Console.ReadLine(text); // we use this value later
LasPoang is the Console.ReadLine() here And Omvandla is the Console.WriteLine() One method needs the values returned by another
J.user
J.userOP7mo ago
So the error is with LasPoang 🤔
Angius
Angius7mo ago
LasPoang is fine The fact that you call it without getting a value out of it, is not You tell someone "chop some onions for me, I'll use them later to make soup" Then you throw away those chopped onions And are surprised that your soup has no onion in it
Onion[] onions = new[];
// get chopped onions
onions = ChopOnions();
// use them in soup
MakeSoup(onions);
Onion[] onions = new[];
// get chopped onions
onions = ChopOnions();
// use them in soup
MakeSoup(onions);
What you are doing is
Onion[] onions = new[];
// where do the chopped onions go?
ChopOnions();
// use... what in soup?
MakeSoup(onions);
Onion[] onions = new[];
// where do the chopped onions go?
ChopOnions();
// use... what in soup?
MakeSoup(onions);
J.user
J.userOP7mo ago
I love your example but does the calling LäsPoäng(ämnen); not use the stored values then?
Angius
Angius7mo ago
Where? How?
J.user
J.userOP7mo ago
in the static void main damn i suck at this lol half of it is like greek
Angius
Angius7mo ago
How does it get the values into the poang array, in your mind?
J.user
J.userOP7mo ago
so omvandla needs to use laspoang somehow trying to figure it out sorry for being such a mess im trying to call laspoang in the omvandla method but that doesnt seem to work either..
Angius
Angius7mo ago
poangs = LasPoang(amnen);
Omvandla(poangs, the other stuff);
poangs = LasPoang(amnen);
Omvandla(poangs, the other stuff);
J.user
J.userOP7mo ago
omg I got it I didnt quite get it but it finally clicked where to write what thank you so much ive been going at this for 4 hours, no kidding im probably the worst beginner there is
Angius
Angius7mo ago
Oh not even close lol We had plenty of threads that spanned days There are people who are just learning-resistant out there
J.user
J.userOP7mo ago
Im most likely one of them lol, I forget half the things I learn ._. I kinda crave for onion soup now
Want results from more Discord servers?
Add your server