C
C#3mo ago
'brella boy

✅ 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
'brella boy
'brella boyOP3mo ago
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
The Father
The Father3mo ago
is the project big?
'brella boy
'brella boyOP3mo ago
No not at al All*
The Father
The Father3mo ago
if not then you can probably use chatgpt to convert it
'brella boy
'brella boyOP3mo ago
Just a few little challenges
The Father
The Father3mo ago
go to chat gpt and convert it
'brella boy
'brella boyOP3mo ago
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
The Father
The Father3mo ago
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
'brella boy
'brella boyOP3mo ago
No description
'brella boy
'brella boyOP3mo ago
The deadline is me sleeping I technically have all night I just wanna get it finished quickly
The Father
The Father3mo ago
LOL alright so what are you trying to do
'brella boy
'brella boyOP3mo ago
Trying to convert farenheight to celcius
The Father
The Father3mo ago
alr
'brella boy
'brella boyOP3mo ago
But uhh idk how equations work in C# I’m getting a bunch of errors
The Father
The Father3mo ago
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
'brella boy
'brella boyOP3mo ago
Alright
The Father
The Father3mo ago
so for F1 you need to put "string" before it so
c#
string F1 = Console.ReadLine();
c#
string F1 = Console.ReadLine();
'brella boy
'brella boyOP3mo ago
Ohhh alright Wait but I want the input to be an integer Or is this a necessary step
The Father
The Father3mo ago
exactly so for F2 you need to make it an int because in this case,
Convert.ToInt32(F1);
Convert.ToInt32(F1);
is converting F1 from a string to an int
'brella boy
'brella boyOP3mo ago
OOOH RIGHT THANKS
The Father
The Father3mo ago
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 type
'brella boy
'brella boyOP3mo ago
Oooh mkay
The Father
The Father3mo ago
then the F2 - 32 follows the equal sign
'brella boy
'brella boyOP3mo ago
So F3 = int F2 - 32; ?
The Father
The Father3mo ago
no int F3 = F2 - 32
'brella boy
'brella boyOP3mo ago
Ah
The Father
The Father3mo ago
like is said you need to specify the data type before the variable you're initializing
c#
string Word;
int myNumber;
float weight;
double skibiditoiletrating;
c#
string Word;
int myNumber;
float weight;
double skibiditoiletrating;
it's like this every time you make a new variable
'brella boy
'brella boyOP3mo ago
I’m getting this error now though
No description
'brella boy
'brella boyOP3mo ago
Wait that sucks
The Father
The Father3mo ago
you didn't specify F2 as an int
'brella boy
'brella boyOP3mo ago
Oh I missed one
The Father
The Father3mo ago
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
'brella boy
'brella boyOP3mo ago
Getting this now
No description
'brella boy
'brella boyOP3mo ago
Code:
No description
The Father
The Father3mo ago
what did you type as the input
'brella boy
'brella boyOP3mo ago
Nothing I instantly got an error Code didn’t run
The Father
The Father3mo ago
ok change int to double double is just a float but 64 bit so it can be way longer
'brella boy
'brella boyOP3mo ago
Alright All 3 of the ints?
The Father
The Father3mo ago
yes it makes more sense anyway considering that temperature can be a double or float anyway
'brella boy
'brella boyOP3mo ago
Only one more error
No description
'brella boy
'brella boyOP3mo ago
Then I’m 1/12 through 🥲
The Father
The Father3mo ago
oh yeah ok so another thing
Keswiik
Keswiik3mo ago
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?
The Father
The Father3mo ago
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)
'brella boy
'brella boyOP3mo ago
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
The Father
The Father3mo ago
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 fine
'brella boy
'brella boyOP3mo ago
Mk
The Father
The Father3mo ago
then it makes the code a little more understandable to humans
'brella boy
'brella boyOP3mo ago
IT WORKED
The Father
The Father3mo ago
ez
'brella boy
'brella boyOP3mo ago
I LOVE YOU SO MUCH THANK YOU
The Father
The Father3mo ago
np
'brella boy
'brella boyOP3mo ago
I’ll try to do some others by myself
The Father
The Father3mo ago
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?
'brella boy
'brella boyOP3mo ago
Nah Only python And not in that much detail tbh
The Father
The Father3mo ago
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
'brella boy
'brella boyOP3mo ago
Also If I want a second subroutine Do I just do repeat static void And name it something other than main?
The Father
The Father3mo ago
soubroutine is just another word for function right? then yes you would
'brella boy
'brella boyOP3mo ago
Yeah Alright
The Father
The Father3mo ago
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 anything
'brella boy
'brella boyOP3mo ago
Alright Running into a bit of an issue I copy and pasted the function But uh Only the Fahrenheit bit runs
The Father
The Father3mo ago
show the source code mmm
'brella boy
'brella boyOP3mo ago
No description
The Father
The Father3mo ago
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 nothing
'brella boy
'brella boyOP3mo ago
How do I call in C# name(); ?
The Father
The Father3mo ago
yes you won't need any arguments for them since you're getting user input
'brella boy
'brella boyOP3mo ago
Minor issue
The Father
The Father3mo ago
show
'brella boy
'brella boyOP3mo ago
No description
The Father
The Father3mo ago
holdup lemme google that
Angius
Angius3mo ago
Bruh Screenshots
'brella boy
'brella boyOP3mo ago
I deleted discord on my pc Nice tanya pfp
The Father
The Father3mo ago
ok make public to static
'brella boy
'brella boyOP3mo ago
Done
The Father
The Father3mo ago
does it work
Angius
Angius3mo ago
public and static re two completely different things btw
The Father
The Father3mo ago
yes
Angius
Angius3mo ago
It can be public static just fine
'brella boy
'brella boyOP3mo ago
Done THANK YOU
The Father
The Father3mo ago
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 static
'brella boy
'brella boyOP3mo ago
Nah never learnt anything in that much detail Alright I’ll attempt the next few on my own
The Father
The Father3mo ago
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
'brella boy
'brella boyOP3mo ago
I do google stuff it’s how I learnt to convert It’s just that Errors kinda suck
Angius
Angius3mo ago
Errors are amazing
'brella boy
'brella boyOP3mo ago
Also I have ONE little issue
Angius
Angius3mo ago
They tell you what's wrong
'brella boy
'brella boyOP3mo ago
To someone who doesn’t program that much They might as well be a foreign languge
The Father
The Father3mo ago
Googling the error:
Angius
Angius3mo ago
No, not really, erros are usually fairly clear and easily googleable
'brella boy
'brella boyOP3mo ago
Well
'brella boy
'brella boyOP3mo ago
No description
'brella boy
'brella boyOP3mo ago
Can this be solved with google
The Father
The Father3mo ago
this
Angius
Angius3mo ago
No need for Google
The Father
The Father3mo ago
"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
'brella boy
'brella boyOP3mo ago
Ohhh OHHH I had them in separate functions
Angius
Angius3mo ago
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
'brella boy
'brella boyOP3mo ago
But idk if combining them is a good idea
Angius
Angius3mo ago
No need to combine anything? $scopes
MODiX
MODiX3mo ago
scope A {
thing a;
scope B {
thing b;
}
}
scope A {
thing a;
scope B {
thing b;
}
}
thing a is available in scope A and scope B thing b is available only in scope B
Angius
Angius3mo ago
If you try accessing b in scope A you get the error
'brella boy
'brella boyOP3mo ago
Oops accidentally made them strings and not doubles They’re all in the same scope I think I’d have to show you
The Father
The Father3mo ago
can you multiply two characters tho? :trollface:
'brella boy
'brella boyOP3mo ago
Angius
Angius3mo ago
No they're not in the same scope You can use things from a parent scope in the child scope Not between siblings
scope A {
thing a;
scope B {
thing b;
}
scope C {
thing c;
}
}
scope A {
thing a;
scope B {
thing b;
}
scope C {
thing c;
}
}
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
'brella boy
'brella boyOP3mo ago
What about ancestors If they’re called that in C# Idk they’re called that in Luau A child of a child
Angius
Angius3mo ago
Same
'brella boy
'brella boyOP3mo ago
Is the child of the child available to the parent
Angius
Angius3mo ago
scope A {
thing a;
scope B {
scope C {
scope D {
can still use `a` here no problem
}
}
}
}
scope A {
thing a;
scope B {
scope C {
scope D {
can still use `a` here no problem
}
}
}
}
'brella boy
'brella boyOP3mo ago
Oooh okay Thanks I’ll try this
The Father
The Father3mo ago
are you referencing roblox dev by chance? because that would be completely different
'brella boy
'brella boyOP3mo ago
Yes
The Father
The Father3mo ago
the problem you're having right now is with scope
'brella boy
'brella boyOP3mo ago
Uhh I only dabbled in roblox
The Father
The Father3mo ago
ancestors and children are related to object-oriented programming
Angius
Angius3mo ago
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
'brella boy
'brella boyOP3mo ago
Is this good?
No description
'brella boy
'brella boyOP3mo ago
Well. It’s not. I’m getting an error
The Father
The Father3mo ago
and a scope isn't an object do you can't use functions like FindFirstAncestor or GetChildren like in roblox studio lua
'brella boy
'brella boyOP3mo ago
But I can’t tell if they’re within different scopes 😭
Angius
Angius3mo ago
{} denote a scope It's simple
The Father
The Father3mo ago
D1 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;
'brella boy
'brella boyOP3mo ago
Alright
The Father
The Father3mo ago
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 it
'brella boy
'brella boyOP3mo ago
Wait I’m getting completely different errors now
The Father
The Father3mo ago
show the code
'brella boy
'brella boyOP3mo ago
No description
'brella boy
'brella boyOP3mo ago
Oh thr code
Angius
Angius3mo ago
Prolly missed a brace somewhere
The Father
The Father3mo ago
do it inside of the class no you put it outside of the class that's why it says toplevel i think
'brella boy
'brella boyOP3mo ago
Angius
Angius3mo ago
ye
The Father
The Father3mo ago
if not then yeah probably forgot a brace ok nvm
Angius
Angius3mo ago
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
'brella boy
'brella boyOP3mo ago
Well
The Father
The Father3mo ago
ok add public before static
'brella boy
'brella boyOP3mo ago
I can re-download discord I really do need the help Alright
The Father
The Father3mo ago
i don't think you can make a variable only static in a class
Angius
Angius3mo ago
Discord works in the browser btw You absolutely can make a static field or property without specifying an access modifier
The Father
The Father3mo ago
hm
Angius
Angius3mo ago
C# will simply default to lowest access, private
'brella boy
'brella boyOP3mo ago
But apparently I have a random account logged into the browser! I can just this there
The Father
The Father3mo ago
just logout
'brella boy
'brella boyOP3mo ago
Nvm I’m logged in
'brella boy
'brella boyOP3mo ago
No description
'brella boy
'brella boyOP3mo ago
No description
The Father
The Father3mo ago
can you copy the text
'brella boy
'brella boyOP3mo ago
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();

} }
The Father
The Father3mo ago
alr i should be able to run it onc ei find out how to rename this file in vscode
Angius
Angius3mo ago
$code
MODiX
MODiX3mo ago
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/
'brella boy
'brella boyOP3mo ago
oh yeah and why cant i run c# in vscode...
cs
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();


}
}
cs
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();


}
}
that didnt work
Angius
Angius3mo ago
` not '
The Father
The Father3mo ago
found it
Angius
Angius3mo ago
Close enough
The Father
The Father3mo ago
delete these
No description
'brella boy
'brella boyOP3mo ago
okie dokie
Angius
Angius3mo ago
None of your methods is terminated with } You got your methods nested within eachother instead
The Father
The Father3mo ago
i wish online compilers had better error stuff vscode is so sexy tho
'brella boy
'brella boyOP3mo ago
i wanna use vscode but it just DOESNT run idk why
Angius
Angius3mo ago
Wym "doesn't run"?
The Father
The Father3mo ago
what type of computer do you have
'brella boy
'brella boyOP3mo ago
No description
'brella boy
'brella boyOP3mo ago
well wdym i built it myself? like windows???
Angius
Angius3mo ago
Says what's wrong You have no project
'brella boy
'brella boyOP3mo ago
well im in one right now right
Angius
Angius3mo ago
C# ain't Python, can't run loose files
The Father
The Father3mo ago
no it's a specific thing
Angius
Angius3mo ago
You need the project file
The Father
The Father3mo ago
a c# project
Angius
Angius3mo ago
.cshtml
'brella boy
'brella boyOP3mo ago
and i make that how
Angius
Angius3mo ago
dotnet new console will create a nice and proper fresh project for you
The Father
The Father3mo ago
in the terminal
'brella boy
'brella boyOP3mo ago
ill.. download it another time
No description
'brella boy
'brella boyOP3mo ago
ok back to errors
'brella boy
'brella boyOP3mo ago
did what you said and got this
No description
The Father
The Father3mo ago
you need to install .NET
Angius
Angius3mo ago
Ah, so you didn't even download .NET and you're wondering why it doesn't run lmao
The Father
The Father3mo ago
do the same thing with A1
'brella boy
'brella boyOP3mo ago
im just a textbook student man
Angius
Angius3mo ago
1. Can't reference non-static members inside of static members 2. Scopes 3. Scopes
'brella boy
'brella boyOP3mo ago
delete two "{"
The Father
The Father3mo ago
no
'brella boy
'brella boyOP3mo ago
OH OOHHH no no i get you
The Father
The Father3mo ago
bro gets me
'brella boy
'brella boyOP3mo ago
apparently
No description
Angius
Angius3mo ago
The function is local
The Father
The Father3mo ago
copy the source doe and send it
Angius
Angius3mo ago
Nested Functions go into classes
The Father
The Father3mo ago
mm
Angius
Angius3mo ago
Functions can go into other functions if you know what you're doing So in this case, let's say they cannot
The Father
The Father3mo ago
send the source code and i'll fix that rq
'brella boy
'brella boyOP3mo ago
oo
using System;

class circles
{

static double D1;
static double A1;

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();


}
}
using System;

class circles
{

static double D1;
static double A1;

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();


}
}
yeah,... i don't.
Angius
Angius3mo ago
I'd tell you to use $prettycode to clean up this unindented mess
MODiX
MODiX3mo ago
To format your code in Visual Studio, Visual Studio Code, Rider, use the following shortcut:
Visual Studio CTRL + K + D
Rider / Resharper CTRL + ALT + L
Visual Studio Code SHIFT + ALT + F
Visual Studio CTRL + K + D
Rider / Resharper CTRL + ALT + L
Visual Studio Code SHIFT + ALT + F
NOTE: the first key must be held while doing it. https://cdn.discordapp.com/attachments/569261465463160900/899513918567890944/2021-10-18_01-26-35.gif
The Father
The Father3mo ago
using System;

class circles
{

static double D1;
static double A1;
// Function 1
static void ONE()
{
Console.WriteLine("Enter the diameter");
string diameter = Console.ReadLine();

// convert to integer
D1 = Convert.ToInt32(diameter);
}
// Function 2
static void TWO()
{
Console.WriteLine("Enter the arc angle");
string aa = Console.ReadLine();

// convert to integer
double A1 = Convert.ToInt32(aa);
}
// Function 3
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();


}
}
using System;

class circles
{

static double D1;
static double A1;
// Function 1
static void ONE()
{
Console.WriteLine("Enter the diameter");
string diameter = Console.ReadLine();

// convert to integer
D1 = Convert.ToInt32(diameter);
}
// Function 2
static void TWO()
{
Console.WriteLine("Enter the arc angle");
string aa = Console.ReadLine();

// convert to integer
double A1 = Convert.ToInt32(aa);
}
// Function 3
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();


}
}
Angius
Angius3mo ago
But I don't suppose it will work with an online compiler
'brella boy
'brella boyOP3mo ago
PRAYING this works i just want to sleep ill firm the fail
The Father
The Father3mo ago
just do it in the online compiler you can google how to setup visual studio tomorrow
'brella boy
'brella boyOP3mo ago
EVERYTHINGS PERFECT AND YOURE A GODSEND except uh... one small issue logic error!
Angius
Angius3mo ago
That's also true, we're talking VS Code here and we should really be talking VS 2022
'brella boy
'brella boyOP3mo ago
arc length isnt right
No description
'brella boy
'brella boyOP3mo ago
it should print this
No description
'brella boy
'brella boyOP3mo ago
not bothering to check anything else but yk
No description
Angius
Angius3mo ago
I'd tell you to use the debugger to check, but... online compiler
'brella boy
'brella boyOP3mo ago
yup uhh
Angius
Angius3mo ago
My bet is it's because of the 360 Try 360.0
'brella boy
'brella boyOP3mo ago
mk also prints 0
Angius
Angius3mo ago
Also, Convert.ToInt32() will just throw an error if you give it something like 123.456, btw
'brella boy
'brella boyOP3mo ago
eh its fine i doubt my teacher will care
Servator
Servator3mo ago
How is your methods access variables ?
'brella boy
'brella boyOP3mo ago
im doing this btw
No description
Servator
Servator3mo ago
$codeblock
'brella boy
'brella boyOP3mo ago
so its arc length thats not working
Angius
Angius3mo ago
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
Servator
Servator3mo ago
Am i missing something?
The Father
The Father3mo ago
send the source doe code again
'brella boy
'brella boyOP3mo ago
mk
The Father
The Father3mo ago
whenever there's a problem and you make a change send the source code
'brella boy
'brella boyOP3mo ago
oh i didnt change anything but
using System;

class circles
{

static double D1;
static double A1;
// Function 1
static void ONE()
{
Console.WriteLine("Enter the diameter");
string diameter = Console.ReadLine();

// convert to integer
D1 = Convert.ToInt32(diameter);
}
// Function 2
static void TWO()
{
Console.WriteLine("Enter the arc angle");
string aa = Console.ReadLine();

// convert to integer
double A1 = Convert.ToInt32(aa);
}
// Function 3
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.0;
Console.WriteLine("The arc length is is:" + AL1);
}

public static void Main(string[] args)
{
ONE();

TWO();

THREE();


}
}
using System;

class circles
{

static double D1;
static double A1;
// Function 1
static void ONE()
{
Console.WriteLine("Enter the diameter");
string diameter = Console.ReadLine();

// convert to integer
D1 = Convert.ToInt32(diameter);
}
// Function 2
static void TWO()
{
Console.WriteLine("Enter the arc angle");
string aa = Console.ReadLine();

// convert to integer
double A1 = Convert.ToInt32(aa);
}
// Function 3
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.0;
Console.WriteLine("The arc length is is:" + AL1);
}

public static void Main(string[] args)
{
ONE();

TWO();

THREE();


}
}
ill double check if my maths is right i guess.. yeah nothing wrong w my maths
MODiX
MODiX3mo ago
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
React with ❌ to remove this embed.
'brella boy
'brella boyOP3mo ago
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
Angius
Angius3mo ago
Console.WriteLine($"({A1} * {CU1}) = {A1 * CU1}");
double AL1 = (A1 * CU1) / 360.0;
Console.WriteLine("The arc length is is:" + AL1);
Console.WriteLine($"({A1} * {CU1}) = {A1 * CU1}");
double AL1 = (A1 * CU1) / 360.0;
Console.WriteLine("The arc length is is:" + AL1);
To see what A1, CU1, and A1 * CU1 are
'brella boy
'brella boyOP3mo ago
No description
'brella boy
'brella boyOP3mo ago
im seeing it.. its arc angle it thinks its 0 for some reason
Angius
Angius3mo ago
No description
Angius
Angius3mo ago
This creates new variable Local to TWO() function It does not assign this value to the A1 field you have in your class
Servator
Servator3mo ago
That's what i was talking about :Sad:
'brella boy
'brella boyOP3mo ago
oooh. so do i fix that by putting it somewhere else..?
Angius
Angius3mo ago
You fix it by removing the double
The Father
The Father3mo ago
oh yeah
Angius
Angius3mo ago
So it assigns to the existing field instead of making a new variable
Servator
Servator3mo ago
No description
Servator
Servator3mo ago
It should output something like this
The Father
The Father3mo ago
also the convert is wrong
Angius
Angius3mo ago
No description
Angius
Angius3mo ago
One works, the other does not
The Father
The Father3mo ago
do Convert.ToDouble
Angius
Angius3mo ago
Take note of the difference
'brella boy
'brella boyOP3mo ago
mk
The Father
The Father3mo ago
replace both of them
Angius
Angius3mo ago
It will be cast to double anyway
The Father
The Father3mo ago
when it converts it to an int it just rounds it
Angius
Angius3mo ago
And if anything, you should just get rid of Convert and use double.Parse()
'brella boy
'brella boyOP3mo ago
will do
Angius
Angius3mo ago
double.TryParse() ideally, but we're not there yet
'brella boy
'brella boyOP3mo ago
No description
'brella boy
'brella boyOP3mo ago
this might be the compiler im using but idk
The Father
The Father3mo ago
ToDouble
Angius
Angius3mo ago
No such thing as Double32 type Yeah
The Father
The Father3mo ago
double is just a 64 bit float
'brella boy
'brella boyOP3mo ago
ahh
The Father
The Father3mo ago
float is 32 bit
Angius
Angius3mo ago
Convert.ToDouble() (eugh. yuck, bad) double.Parse() (eh, sure, will do) Either of those works
'brella boy
'brella boyOP3mo ago
SUCCESS!! you're all Godsends now I'm going to sleep before I actually die
No description
The Father
The Father3mo ago
ez
'brella boy
'brella boyOP3mo ago
thank you for your time.
The Father
The Father3mo ago
np why is parse better i know why TryParse is but no Parse
Angius
Angius3mo ago
Convert will take a null and gladly treat it as a 0
MODiX
MODiX3mo ago
Angius
REPL Result: Success
Convert.ToInt32(null)
Convert.ToInt32(null)
Result: int
0
0
Compile: 411.577ms | Execution: 18.054ms | React with ❌ to remove this embed.
The Father
The Father3mo ago
hm
MODiX
MODiX3mo ago
Angius
REPL Result: Failure
int.Parse(null)
int.Parse(null)
Exception: ArgumentNullException
- Value cannot be null. (Parameter 's')
- Value cannot be null. (Parameter 's')
Compile: 305.950ms | Execution: 24.735ms | React with ❌ to remove this embed.
Angius
Angius3mo ago
You gotta remember that Console.ReadLine() returns a string? not a string So it's best to handle that possible null properly
The Father
The Father3mo ago
ohh i didn't know that
Angius
Angius3mo ago
Well, properly-ish
The Father
The Father3mo ago
because the null terminator?
Angius
Angius3mo ago
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 cases
The Father
The Father3mo ago
hm
'brella boy
'brella boyOP3mo ago
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
Angius
Angius3mo ago
Sure
'brella boy
'brella boyOP3mo ago
oh nvm i fixed it im actually learning 🥹
Angius
Angius3mo ago
'Ere you go1
'brella boy
'brella boyOP3mo ago
nope nvm
Angius
Angius3mo ago
:kekw:
'brella boy
'brella boyOP3mo ago
the C2F is just kinda excess but uh
No description
'brella boy
'brella boyOP3mo ago
for once my code isnt a muddlke
Angius
Angius3mo ago
Did you perhaps mean to use else if? Also, use braces, they make things cleaner This ain't Python
'brella boy
'brella boyOP3mo ago
where do i put the... brackets?
No description
'brella boy
'brella boyOP3mo ago
they still confuse me but ill try
Angius
Angius3mo ago
if (something)
{
// do stuff
}
else if (something_else)
{
// do other stuff
}
else
{
// do another stuff entirely
}
if (something)
{
// do stuff
}
else if (something_else)
{
// do other stuff
}
else
{
// do another stuff entirely
}
'brella boy
'brella boyOP3mo ago
but like else if... what?
'brella boy
'brella boyOP3mo ago
No description
'brella boy
'brella boyOP3mo ago
ill use the braces ty
Angius
Angius3mo ago
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
Angius
Angius3mo ago
No description
Angius
Angius3mo ago
here
'brella boy
'brella boyOP3mo ago
oooh mk
'brella boy
'brella boyOP3mo ago
No description
'brella boy
'brella boyOP3mo ago
so like this? and i THINK thats how braces are
Angius
Angius3mo ago
yep
'brella boy
'brella boyOP3mo ago
i must be doing something wrong..
No description
Angius
Angius3mo ago
I see no errors
'brella boy
'brella boyOP3mo ago
it might be the code thingy im using
Angius
Angius3mo ago
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
'brella boy
'brella boyOP3mo ago
i was using dotnet fiddle but it just kinda crashes
Angius
Angius3mo ago
Right And Sharplab does not allow for user input So ig keep chugging along, using what you're using
'brella boy
'brella boyOP3mo ago
ill just submit this anyway and hope the teacher doesnt notice even though im literally only half done 😊
Angius
Angius3mo ago
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
'brella boy
'brella boyOP3mo ago
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
Angius
Angius3mo ago
% will be your friend And Math.Round() method
'brella boy
'brella boyOP3mo ago
mk 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
Angius
Angius3mo ago
ye
'brella boy
'brella boyOP3mo ago
ok ill try that
Angius
Angius3mo ago
That works too, no need for %
'brella boy
'brella boyOP3mo ago
do I
No description
'brella boy
'brella boyOP3mo ago
REALLY have to separate them AGAIN
Angius
Angius3mo ago
No, why?
'brella boy
'brella boyOP3mo ago
well whys it saying they dont exist
Angius
Angius3mo ago
Yeah M2 = 7; is assigning the value of 7 to an existing M2
'brella boy
'brella boyOP3mo ago
ooooooooooh
Angius
Angius3mo ago
It has never actually been declared anywhere
'brella boy
'brella boyOP3mo ago
so. where do I declare it?
Angius
Angius3mo ago
So double M2 = ...
'brella boy
'brella boyOP3mo ago
should I just set it to 0 beforehand and let it update
Angius
Angius3mo ago
No, you can do it on one line You can do
int x;
x = 69;
int x;
x = 69;
or
int x = 0;
x = 69;
int x = 0;
x = 69;
but it's just useless code, You can just do
int x = 69;
int x = 69;
like you've been doing
'brella boy
'brella boyOP3mo ago
ahhh mk
'brella boy
'brella boyOP3mo ago
sorry for bombarding you with problems that probably have easy solutions but
No description
'brella boy
'brella boyOP3mo ago
im so tired rn and i cant think straight i just need to get this do ne
'brella boy
'brella boyOP3mo ago
No description
'brella boy
'brella boyOP3mo ago
nvm fixed one it works thanks not bad considering I started learning C# 3 and a half hours ago
Angius
Angius3mo ago
Yeah lol
'brella boy
'brella boyOP3mo ago
and once again, nice tanya pfp real underrated show
Angius
Angius3mo ago
Oh yeah Can't wait for S2
'brella boy
'brella boyOP3mo ago
ITS COMING ?
Angius
Angius3mo ago
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?
'brella boy
'brella boyOP3mo ago
Surely not. I'm almost caught up on the manga and don't want to have to wait just yet..
Evyr
Evyr3mo ago
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
'brella boy
'brella boyOP3mo ago
So it’ll never round up to an odd number? Weird… Well I’ll keep that in consideration thanks
Evyr
Evyr3mo ago
iirc it's do to with rounding conventions in finance, or something like that
'brella boy
'brella boyOP3mo ago
Ah
Want results from more Discord servers?
Add your server