✅ I DESPERATELY NEED HELP GETTING STARTED
I have 1-2 hours left before a deadline and I only just realised the entire thing is in C#. I need help. Please.
332 Replies
I know how to program but in python and not C#
So it won’t take ages and I’ve already learnt some parameters I just have no idea what I’m doing wrong at the moment
is the project big?
No not at al
All*
if not then you can probably use chatgpt to convert it
Just a few little challenges
go to chat gpt and convert it
But like I don’t learn that way
I don’t wanna be cheap I just want some advice
I can give you an example hold on
trust me blud if you have an important deadline in less than 2 hours i highly suggest you use chatgpt right now
but i'd be willing to help anyway
The deadline is me sleeping I technically have all night
I just wanna get it finished quickly
LOL alright
so what are you trying to do
Trying to convert farenheight to celcius
alr
But uhh idk how equations work in C#
I’m getting a bunch of errors
ok so first you need to know something
unlike in python, c# is a static language
so that means that the data type of variables must be specified before you assign them
Alright
so for F1
you need to put "string" before it
so
Ohhh alright
Wait but I want the input to be an integer
Or is this a necessary step
exactly
so for F2 you need to make it an int
because in this case, is converting
F1
from a string to an intOOOH
RIGHT
THANKS
mhm
and for
int F2 - 32 = F3
you did it the opposite way
first of all it's still similar to python
so you say the variable name first
and then like in c# you need to specify the data typeOooh mkay
then the
F2 - 32
follows the equal signSo
F3 = int F2 - 32;
?
no
int F3 = F2 - 32
Ah
like is said you need to specify the data type before the variable you're initializing
it's like this every time you make a new variable
I’m getting this error now though
Wait that sucks
you didn't specify
F2
as an intOh I missed one
you got a string from the user input and stored it in
F1
then you convert that string to an int and store it in another variable
being F2
Getting this now
Code:
what did you type as the input
Nothing I instantly got an error
Code didn’t run
ok change
int
to double
double is just a float but 64 bit
so it can be way longerAlright
All 3 of the ints?
yes
it makes more sense anyway considering that temperature can be a double or float anyway
Only one more error
Then I’m 1/12 through 🥲
oh yeah
ok so another thing
how exactly did you get an assignment in a language you don't know, then not realize it until the deadline is a couple hours away?
in C based languages like C, C++ and C# you need to have a function called "Main" as an entrypoint for the program
so rename "FareignheitToCentritrade" to "Main"
so
Main(string[] args)
I’m going to a new school, and I only made up my mind about which school I was going to very recently, and neglected to think that they might be doing a different programming language from my old school, with only a day remaining. It’s supposed to be 3 hours of 16 hours that I’ve completed
Alright
every single c# program must have and can only have one function named
Main
if it doesn't then it doesn't know how to link, compile, blah blah blah
stupid C-like language buzzwords
you can change the class Program
to FahrenheitToCentrigrade
that's fineMk
then it makes the code a little more understandable to humans
IT WORKED
ez
I LOVE YOU SO MUCH THANK YOU
np
I’ll try to do some others by myself
alr
note that there are a lot of things that you'll have to get used to about c# and other static languages
because it's VERY different than python
have you worked with other languages before?
Nah
Only python
And not in that much detail tbh
then you're gonna have to adjust quite a bit but if you don't have much python experience it shouldn't be that bad
Also
If I want a second subroutine
Do I just do repeat static void
And name it something other than main?
soubroutine is just another word for function right?
then yes you would
Yeah
Alright
although you don't need to use the static modifier for it
you can either put "public", "private" or "static"
but just put public for now
probably the safest option for later
but you do need to make the
Main
function static
also
if you want to make a function that returns a value, then you need to replace void
with the data type
void
just means the function doesn't return anythingAlright
Running into a bit of an issue
I copy and pasted the function
But uh
Only the Fahrenheit bit runs
show the source code
mmm
i understand the problem
ok so
rename both of the functions to what they're supposed to be named
then make another function called
Main
then call both of the functions from that main Main
and replace the string[] args
with nothingHow do I call in C#
name();
?
yes
you won't need any arguments for them since you're getting user input
Minor issue
show
holdup lemme google that
Bruh
Screenshots
I deleted discord on my pc
Nice tanya pfp
ok make
public
to static
Done
does it work
public
and static
re two completely different things btwyes
It can be
public static
just fineDone
THANK YOU
oh yeah
np
though ignore the
public
and private
keywords for now
do you know python classes yet?
if not then the words mean nothing to you for now
just make everything staticNah never learnt anything in that much detail
Alright I’ll attempt the next few on my own
ez
don't forget to google stuff
the microsoft .net documentation is dope so when you have a problem just google it
and click the first microsoft or stackoverflow link you see
I do google stuff it’s how I learnt to convert
It’s just that
Errors kinda suck
Errors are amazing
Also I have ONE little issue
They tell you what's wrong
To someone who doesn’t program that much
They might as well be a foreign languge
Googling the error:
No, not really, erros are usually fairly clear and easily googleable
Well
Can this be solved with google
this
No need for Google
"this name does not exist in the current context"
though it should be very easy to fix
the variable just doesn't exist in that scope
that you're trying to access it from
Ohhh
OHHH
I had them in separate functions
1. You're trying to use a thing that does not exist
2. You're trying to multiply two strings, which is not a thing
3. Same as 1
4. Same as 1
But idk if combining them is a good idea
No need to combine anything?
$scopes
thing a
is available in scope A
and scope B
thing b
is available only in scope B
If you try accessing
b
in scope A
you get the errorOops accidentally made them strings and not doubles
They’re all in the same scope I think
I’d have to show you
can you multiply two characters tho? :trollface:
No they're not in the same scope
You can use things from a parent scope in the child scope
Not between siblings
thing a
is available in scopes B
and C
thing b
is available only in scope B
thing c
is available only in scope C
What about ancestors
If they’re called that in C#
Idk they’re called that in Luau
A child of a child
Same
Is the child of the child available to the parent
Oooh okay
Thanks I’ll try this
are you referencing roblox dev by chance?
because that would be completely different
Yes
the problem you're having right now is with scope
Uhh I only dabbled in roblox
ancestors and children are related to object-oriented programming
Ah, yeah, two different things
I'm using terms "parent scope", "child scope", etc. only loosely
It's really about nesting, to be more precise
A scope has access to the things within it, and things in all scopes it's nested within
Is this good?
Well. It’s not. I’m getting an error
and a scope isn't an object do you can't use functions like
FindFirstAncestor
or GetChildren
like in roblox studio luaBut I can’t tell if they’re within different scopes 😭
{}
denote a scope
It's simpleD1
is in the scope of ONE()
if you want to store D1 within the parent scope you need to make a variable within there
ok so do this
make a variable within the whole class
so before any of the functions
and just type double D1;
Alright
static double D1
excuse me
and then in the ONE
function
remove the double
keyword
since you're not initializing it you don't need to specify the data type
you're just assigning itWait I’m getting completely different errors now
show the code
Oh thr code
Prolly missed a brace somewhere
do it inside of the class
no you put it outside of the class
that's why it says toplevel
i think
ye
if not then yeah probably forgot a brace
ok nvm
Yeah, you know what, I'm out. I don't fancy having to fullscreen red-tinted vertical videos to take a look at the code
Peace
Well
ok add
public
before static
I can re-download discord
I really do need the help
Alright
i don't think you can make a variable only static in a class
Discord works in the browser btw
You absolutely can make a static field or property without specifying an access modifier
hm
C# will simply default to lowest access,
private
But apparently I have a random account logged into the browser! I can just this there
just logout
Nvm I’m logged in
can you copy the text
makes sense
using System;
class circles {
static double D1;
static void ONE() { Console.WriteLine("Enter the diameter"); string diameter = Console.ReadLine();
// convert to integer D1 = Convert.ToInt32(diameter);
static void TWO() { Console.WriteLine("Enter the arc angle"); string aa = Console.ReadLine();
// convert to integer double A1 = Convert.ToInt32(aa);
static void THREE() {
double R1 = D1 / 2; Console.WriteLine("The radius is:" + R1);
double AR1 = 3.14 + (R1 * R1); Console.WriteLine("The area is:" + AR1);
double CU1 = 3.14 * D1; Console.WriteLine("The circumference is:" + CU1);
double AL1 = (A1 * CU1) / 360; Console.WriteLine("The arc length is is:" + AL1);
} } } }
}
public static void Main(string[] args) { ONE();
TWO();
THREE();
} }
class circles {
static double D1;
static void ONE() { Console.WriteLine("Enter the diameter"); string diameter = Console.ReadLine();
// convert to integer D1 = Convert.ToInt32(diameter);
static void TWO() { Console.WriteLine("Enter the arc angle"); string aa = Console.ReadLine();
// convert to integer double A1 = Convert.ToInt32(aa);
static void THREE() {
double R1 = D1 / 2; Console.WriteLine("The radius is:" + R1);
double AR1 = 3.14 + (R1 * R1); Console.WriteLine("The area is:" + AR1);
double CU1 = 3.14 * D1; Console.WriteLine("The circumference is:" + CU1);
double AL1 = (A1 * CU1) / 360; Console.WriteLine("The arc length is is:" + AL1);
} } } }
}
public static void Main(string[] args) { ONE();
TWO();
THREE();
} }
alr i should be able to run it
onc ei find out how to rename this file in vscode
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/oh yeah and why cant i run c# in vscode...
that didnt work
` not '
found it
Close enough
delete these
okie dokie
None of your methods is terminated with
}
You got your methods nested within eachother insteadi wish online compilers had better error stuff
vscode is so sexy tho
i wanna use vscode but it just DOESNT run
idk why
Wym "doesn't run"?
what type of computer do you have
well wdym
i built it myself?
like windows???
Says what's wrong
You have no project
well im in one right now right
C# ain't Python, can't run loose files
no it's a specific thing
You need the project file
a c# project
.cshtml
and i make that how
dotnet new console
will create a nice and proper fresh project for youin the terminal
ill.. download it another time
ok back to errors
did what you said and got this
you need to install .NET
Ah, so you didn't even download .NET and you're wondering why it doesn't run lmao
do the same thing with A1
im just a textbook student man
1. Can't reference non-static members inside of static members
2. Scopes
3. Scopes
delete two "{"
no
OH
OOHHH
no no i get you
bro gets me
apparently
The function is local
copy the source doe and send it
Nested
Functions go into classes
mm
Functions can go into other functions if you know what you're doing
So in this case, let's say they cannot
send the source code and i'll fix that rq
oo
yeah,... i don't.
I'd tell you to use $prettycode to clean up this unindented mess
To format your code in Visual Studio, Visual Studio Code, Rider, use the following shortcut:
NOTE: the first key must be held while doing it.
https://cdn.discordapp.com/attachments/569261465463160900/899513918567890944/2021-10-18_01-26-35.gif
But I don't suppose it will work with an online compiler
PRAYING this works i just want to sleep
ill firm the fail
just do it in the online compiler
you can google how to setup visual studio tomorrow
EVERYTHINGS PERFECT
AND
YOURE A GODSEND
except
uh...
one small issue
logic error!
That's also true, we're talking VS Code here and we should really be talking VS 2022
arc length isnt right
it should print this
not bothering to check anything else but yk
I'd tell you to use the debugger to check, but... online compiler
yup
uhh
My bet is it's because of the 360
Try
360.0
mk
also prints 0
Also,
Convert.ToInt32()
will just throw an error if you give it something like 123.456
, btweh
its fine
i doubt my teacher will care
How is your methods access variables ?
im doing this btw
$codeblock
so its arc length thats not working
We can do the debugging the hard way. Before the calculation that goes wrong, print out all of its components to see what they are
Am i missing something?
send the source doe
code
again
mk
whenever there's a problem and you make a change send the source code
oh i didnt change anything but
ill double check if my maths is right i guess..
yeah nothing wrong w my maths
Angius
We can do the debugging the hard way. Before the calculation that goes wrong, print out all of its components to see what they are
Quoted by
<@85903769203642368> from #I DESPERATELY NEED HELP GETTING STARTED (click here)
React with ❌ to remove this embed.
i mean i basically do
with radius, area and circumference
since arc length is just arc angle and circumference
but i mean
ill reprint it yeah
To see what
A1
, CU1
, and A1 * CU1
areim seeing it..
its arc angle
it thinks its 0
for some reason
This creates new variable
Local to
TWO()
function
It does not assign this value to the A1
field you have in your classThat's what i was talking about :Sad:
oooh.
so do i fix that by putting it somewhere else..?
You fix it by removing the
double
oh yeah
So it assigns to the existing field instead of making a new variable
It should output something like this
also the convert is wrong
One works, the other does not
do
Convert.ToDouble
Take note of the difference
mk
replace both of them
It will be cast to double anyway
when it converts it to an int it just rounds it
And if anything, you should just get rid of
Convert
and use double.Parse()
will do
double.TryParse()
ideally, but we're not there yetthis might be
the compiler im using
but idk
ToDouble
No such thing as
Double32
type
Yeahdouble is just a 64 bit float
ahh
float is 32 bit
Convert.ToDouble()
(eugh. yuck, bad)
double.Parse()
(eh, sure, will do)
Either of those worksSUCCESS!! you're all Godsends now I'm going to sleep before I actually die
ez
thank you for your time.
np
why is parse better
i know why TryParse is but no Parse
Convert
will take a null
and gladly treat it as a 0
Angius
REPL Result: Success
Result: int
Compile: 411.577ms | Execution: 18.054ms | React with ❌ to remove this embed.
hm
Angius
REPL Result: Failure
Exception: ArgumentNullException
Compile: 305.950ms | Execution: 24.735ms | React with ❌ to remove this embed.
You gotta remember that
Console.ReadLine()
returns a string?
not a string
So it's best to handle that possible null properlyohh i didn't know that
Well, properly-ish
because the null terminator?
ye
Actually
Ctrl+Z
followed by Enter
will send a null
for example
Also, other applications can just send a null stream and what not
Lotsa edge caseshm
oh man im supposed to make like 3-6 more programs
😭
can anyone help me with 1 more error? its just a simple one though
didnt pick complicated code this time
Sure
oh nvm
i fixed it
im actually learning
🥹
'Ere you go1
nope nvm
:kekw:
the C2F is just kinda excess but uh
for once my code isnt a muddlke
Did you perhaps mean to use
else if
?
Also, use braces, they make things cleaner
This ain't Pythonwhere do i put the... brackets?
they still confuse me but ill try
but like else if... what?
ill use the braces ty
If job is engineer, else if the job is developer, else if the job is fisherman, else if the job is a waiter, else there's no job
here
oooh
mk
so like this?
and i THINK thats how braces are
yep
i must be doing something wrong..
I see no errors
it might be the code thingy im using
Idk what you're using, but when it comes to online compilers Sharplab and Dotnet Fiddle are the only ones I see recommended
The proper recommendation of course is to just use VS 2022
But far as web goes, it's those two
i was using dotnet fiddle but it just kinda crashes
Right
And Sharplab does not allow for user input
So ig keep chugging along, using what you're using
ill just submit this anyway and hope the teacher doesnt notice
even though im literally only half done
😊
Would've gone so much faster and easier if you just installed VS 2022
Code completion, errors shown even before the code is ran, all that good stuff
alr
wait
i got one more in me...
this one requires a bit of explanation though
ok so
i need to
input a sum of money
lets say
£24.50
and i need the program
to round it up
to the nearest £
so in this case
£25
and then "deposit" the change
which would be
0.50
%
will be your friend
And Math.Round()
methodmk so
i get the user to input a number
which is
double
right?
then I use math.round to round it up
then i do
rounded up number - initial number
ye
ok ill try that
That works too, no need for
%
do I
REALLY have to separate them
AGAIN
No, why?
well whys it saying they dont exist
Yeah
M2 = 7;
is assigning the value of 7
to an existing M2
ooooooooooh
It has never actually been declared anywhere
so.
where do I declare it?
So
double M2 = ...
should I just set it to 0
beforehand
and let it update
No, you can do it on one line
You can do
or
but it's just useless code, You can just do
like you've been doing
ahhh mk
sorry for bombarding you with problems that probably have easy solutions but
im so tired rn and i cant think straight
i just need to get this do ne
nvm fixed one
it works
thanks
not bad considering I started learning C# 3 and a half hours ago
Yeah lol
and once again, nice tanya pfp
real underrated show
Oh yeah
Can't wait for S2
ITS COMING
?
It is, we just don't know when, yet
Been a good while since they released the movie, though
So it can't be that much longer, can it?
Surely not. I'm almost caught up on the manga and don't want to have to wait just yet..
be wary with Math.Round, by default it rounds to even. There's an overload that lets you pass in a MidPointRounding enum, eg MidPointRounding.AwayFromZero which would behave as you'd expect rounding to normally
So it’ll never round up to an odd number?
Weird…
Well I’ll keep that in consideration thanks
iirc it's do to with rounding conventions in finance, or something like that
Ah