C
C#2w 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
Angius2w ago
Try debugging this code $debug
MODiX
MODiX2w 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
Angius2w 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.user2w ago
Im not quite sure what you mean 😢
Angius
Angius2w 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.user2w 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
Angius2w 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.user2w ago
You call it in the main code?
Angius
Angius2w ago
No description
Angius
Angius2w 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.user2w ago
Trying to understand and do this😅 Thank you btw for taking your time and looking over my bad code
Angius
Angius2w 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.user2w ago
So the error is with LasPoang 🤔
Angius
Angius2w 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.user2w ago
I love your example but does the calling LäsPoäng(ämnen); not use the stored values then?
Angius
Angius2w ago
Where? How?
J.user
J.user2w ago
in the static void main damn i suck at this lol half of it is like greek
Angius
Angius2w ago
How does it get the values into the poang array, in your mind?
J.user
J.user2w 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
Angius2w ago
poangs = LasPoang(amnen);
Omvandla(poangs, the other stuff);
poangs = LasPoang(amnen);
Omvandla(poangs, the other stuff);
J.user
J.user2w 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
Angius2w 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.user2w ago
Im most likely one of them lol, I forget half the things I learn ._. I kinda crave for onion soup now