C
C#4mo ago
rigamortus

✅ 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
rigamortus
rigamortusOP4mo 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 Father4mo ago
is the project big?
rigamortus
rigamortusOP4mo ago
No not at al All*
The Father
The Father4mo ago
if not then you can probably use chatgpt to convert it
rigamortus
rigamortusOP4mo ago
Just a few little challenges
The Father
The Father4mo ago
go to chat gpt and convert it
rigamortus
rigamortusOP4mo 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 Father4mo 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
rigamortus
rigamortusOP4mo ago
No description
rigamortus
rigamortusOP4mo ago
The deadline is me sleeping I technically have all night I just wanna get it finished quickly
The Father
The Father4mo ago
LOL alright so what are you trying to do
rigamortus
rigamortusOP4mo ago
Trying to convert farenheight to celcius
The Father
The Father4mo ago
alr
rigamortus
rigamortusOP4mo ago
But uhh idk how equations work in C# I’m getting a bunch of errors
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo ago
Alright
The Father
The Father4mo ago
so for F1 you need to put "string" before it so
c#
string F1 = Console.ReadLine();
c#
string F1 = Console.ReadLine();
rigamortus
rigamortusOP4mo ago
Ohhh alright Wait but I want the input to be an integer Or is this a necessary step
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo ago
OOOH RIGHT THANKS
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo ago
Oooh mkay
The Father
The Father4mo ago
then the F2 - 32 follows the equal sign
rigamortus
rigamortusOP4mo ago
So F3 = int F2 - 32; ?
The Father
The Father4mo ago
no int F3 = F2 - 32
rigamortus
rigamortusOP4mo ago
Ah
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo ago
I’m getting this error now though
No description
rigamortus
rigamortusOP4mo ago
Wait that sucks
The Father
The Father4mo ago
you didn't specify F2 as an int
rigamortus
rigamortusOP4mo ago
Oh I missed one
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo ago
Getting this now
No description
rigamortus
rigamortusOP4mo ago
Code:
No description
The Father
The Father4mo ago
what did you type as the input
rigamortus
rigamortusOP4mo ago
Nothing I instantly got an error Code didn’t run
The Father
The Father4mo ago
ok change int to double double is just a float but 64 bit so it can be way longer
rigamortus
rigamortusOP4mo ago
Alright All 3 of the ints?
The Father
The Father4mo ago
yes it makes more sense anyway considering that temperature can be a double or float anyway
rigamortus
rigamortusOP4mo ago
Only one more error
No description
rigamortus
rigamortusOP4mo ago
Then I’m 1/12 through 🥲
The Father
The Father4mo ago
oh yeah ok so another thing
Keswiik
Keswiik4mo 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 Father4mo 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)
rigamortus
rigamortusOP4mo 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 Father4mo 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
rigamortus
rigamortusOP4mo ago
Mk
The Father
The Father4mo ago
then it makes the code a little more understandable to humans
rigamortus
rigamortusOP4mo ago
IT WORKED
The Father
The Father4mo ago
ez
rigamortus
rigamortusOP4mo ago
I LOVE YOU SO MUCH THANK YOU
The Father
The Father4mo ago
np
rigamortus
rigamortusOP4mo ago
I’ll try to do some others by myself
The Father
The Father4mo 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?
rigamortus
rigamortusOP4mo ago
Nah Only python And not in that much detail tbh
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo 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 Father4mo ago
soubroutine is just another word for function right? then yes you would
rigamortus
rigamortusOP4mo ago
Yeah Alright
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo 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 Father4mo ago
show the source code mmm
rigamortus
rigamortusOP4mo ago
No description
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo ago
How do I call in C# name(); ?
The Father
The Father4mo ago
yes you won't need any arguments for them since you're getting user input
rigamortus
rigamortusOP4mo ago
Minor issue
The Father
The Father4mo ago
show
rigamortus
rigamortusOP4mo ago
No description
The Father
The Father4mo ago
holdup lemme google that
Angius
Angius4mo ago
Bruh Screenshots
rigamortus
rigamortusOP4mo ago
I deleted discord on my pc Nice tanya pfp
The Father
The Father4mo ago
ok make public to static
rigamortus
rigamortusOP4mo ago
Done
The Father
The Father4mo ago
does it work
Angius
Angius4mo ago
public and static re two completely different things btw
The Father
The Father4mo ago
yes
Angius
Angius4mo ago
It can be public static just fine
rigamortus
rigamortusOP4mo ago
Done THANK YOU
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo ago
Nah never learnt anything in that much detail Alright I’ll attempt the next few on my own
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo ago
I do google stuff it’s how I learnt to convert It’s just that Errors kinda suck
Angius
Angius4mo ago
Errors are amazing
rigamortus
rigamortusOP4mo ago
Also I have ONE little issue
Angius
Angius4mo ago
They tell you what's wrong
rigamortus
rigamortusOP4mo ago
To someone who doesn’t program that much They might as well be a foreign languge
The Father
The Father4mo ago
Googling the error:
Angius
Angius4mo ago
No, not really, erros are usually fairly clear and easily googleable
rigamortus
rigamortusOP4mo ago
Well
rigamortus
rigamortusOP4mo ago
No description
rigamortus
rigamortusOP4mo ago
Can this be solved with google
The Father
The Father4mo ago
this
Angius
Angius4mo ago
No need for Google
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo ago
Ohhh OHHH I had them in separate functions
Angius
Angius4mo 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
rigamortus
rigamortusOP4mo ago
But idk if combining them is a good idea
Angius
Angius4mo ago
No need to combine anything? $scopes
MODiX
MODiX4mo 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
Angius4mo ago
If you try accessing b in scope A you get the error
rigamortus
rigamortusOP4mo 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 Father4mo ago
can you multiply two characters tho? :trollface:
rigamortus
rigamortusOP4mo ago
Angius
Angius4mo 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
rigamortus
rigamortusOP4mo ago
What about ancestors If they’re called that in C# Idk they’re called that in Luau A child of a child
Angius
Angius4mo ago
Same
rigamortus
rigamortusOP4mo ago
Is the child of the child available to the parent
Angius
Angius4mo 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
}
}
}
}
rigamortus
rigamortusOP4mo ago
Oooh okay Thanks I’ll try this
The Father
The Father4mo ago
are you referencing roblox dev by chance? because that would be completely different
rigamortus
rigamortusOP4mo ago
Yes
The Father
The Father4mo ago
the problem you're having right now is with scope
rigamortus
rigamortusOP4mo ago
Uhh I only dabbled in roblox
The Father
The Father4mo ago
ancestors and children are related to object-oriented programming
Angius
Angius4mo 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
rigamortus
rigamortusOP4mo ago
Is this good?
No description
rigamortus
rigamortusOP4mo ago
Well. It’s not. I’m getting an error
The Father
The Father4mo ago
and a scope isn't an object do you can't use functions like FindFirstAncestor or GetChildren like in roblox studio lua
rigamortus
rigamortusOP4mo ago
But I can’t tell if they’re within different scopes 😭
Angius
Angius4mo ago
{} denote a scope It's simple
The Father
The Father4mo 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;
rigamortus
rigamortusOP4mo ago
Alright
The Father
The Father4mo 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
rigamortus
rigamortusOP4mo ago
Wait I’m getting completely different errors now
The Father
The Father4mo ago
show the code
rigamortus
rigamortusOP4mo ago
No description
rigamortus
rigamortusOP4mo ago
Oh thr code
Angius
Angius4mo ago
Prolly missed a brace somewhere
The Father
The Father4mo ago
do it inside of the class no you put it outside of the class that's why it says toplevel i think
rigamortus
rigamortusOP4mo ago
Angius
Angius4mo ago
ye
The Father
The Father4mo ago
if not then yeah probably forgot a brace ok nvm
Angius
Angius4mo 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
rigamortus
rigamortusOP4mo ago
Well
The Father
The Father4mo ago
ok add public before static
rigamortus
rigamortusOP4mo ago
I can re-download discord I really do need the help Alright
The Father
The Father4mo ago
i don't think you can make a variable only static in a class
Angius
Angius4mo ago
Discord works in the browser btw You absolutely can make a static field or property without specifying an access modifier
The Father
The Father4mo ago
hm
Angius
Angius4mo ago
C# will simply default to lowest access, private
rigamortus
rigamortusOP4mo ago
But apparently I have a random account logged into the browser! I can just this there
The Father
The Father4mo ago
just logout
rigamortus
rigamortusOP4mo ago
Nvm I’m logged in
rigamortus
rigamortusOP4mo ago
No description
rigamortus
rigamortusOP4mo ago
No description
The Father
The Father4mo ago
can you copy the text
rigamortus
rigamortusOP4mo 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 Father4mo ago
alr i should be able to run it onc ei find out how to rename this file in vscode
Angius
Angius4mo ago
$code
MODiX
MODiX4mo 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/
rigamortus
rigamortusOP4mo 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
Angius4mo ago
` not '
The Father
The Father4mo ago
found it
Angius
Angius4mo ago
Close enough
The Father
The Father4mo ago
delete these
No description
rigamortus
rigamortusOP4mo ago
okie dokie
Angius
Angius4mo ago
None of your methods is terminated with } You got your methods nested within eachother instead
The Father
The Father4mo ago
i wish online compilers had better error stuff vscode is so sexy tho
rigamortus
rigamortusOP4mo ago
i wanna use vscode but it just DOESNT run idk why
Angius
Angius4mo ago
Wym "doesn't run"?
The Father
The Father4mo ago
what type of computer do you have
rigamortus
rigamortusOP4mo ago
No description
rigamortus
rigamortusOP4mo ago
well wdym i built it myself? like windows???
Angius
Angius4mo ago
Says what's wrong You have no project
rigamortus
rigamortusOP4mo ago
well im in one right now right
Angius
Angius4mo ago
C# ain't Python, can't run loose files
The Father
The Father4mo ago
no it's a specific thing
Angius
Angius4mo ago
You need the project file
The Father
The Father4mo ago
a c# project
Angius
Angius4mo ago
.cshtml
rigamortus
rigamortusOP4mo ago
and i make that how
Angius
Angius4mo ago
dotnet new console will create a nice and proper fresh project for you
The Father
The Father4mo ago
in the terminal
rigamortus
rigamortusOP4mo ago
ill.. download it another time
No description
rigamortus
rigamortusOP4mo ago
ok back to errors
rigamortus
rigamortusOP4mo ago
did what you said and got this
No description
The Father
The Father4mo ago
you need to install .NET
Angius
Angius4mo ago
Ah, so you didn't even download .NET and you're wondering why it doesn't run lmao
The Father
The Father4mo ago
do the same thing with A1
rigamortus
rigamortusOP4mo ago
im just a textbook student man
Angius
Angius4mo ago
1. Can't reference non-static members inside of static members 2. Scopes 3. Scopes
rigamortus
rigamortusOP4mo ago
delete two "{"
The Father
The Father4mo ago
no
rigamortus
rigamortusOP4mo ago
OH OOHHH no no i get you
The Father
The Father4mo ago
bro gets me
rigamortus
rigamortusOP4mo ago
apparently
No description
Angius
Angius4mo ago
The function is local
The Father
The Father4mo ago
copy the source doe and send it
Angius
Angius4mo ago
Nested Functions go into classes
The Father
The Father4mo ago
mm
Angius
Angius4mo 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 Father4mo ago
send the source code and i'll fix that rq
rigamortus
rigamortusOP4mo 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
Angius4mo ago
I'd tell you to use $prettycode to clean up this unindented mess
MODiX
MODiX4mo 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 Father4mo 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
Angius4mo ago
But I don't suppose it will work with an online compiler
rigamortus
rigamortusOP4mo ago
PRAYING this works i just want to sleep ill firm the fail
The Father
The Father4mo ago
just do it in the online compiler you can google how to setup visual studio tomorrow
rigamortus
rigamortusOP4mo ago
EVERYTHINGS PERFECT AND YOURE A GODSEND except uh... one small issue logic error!
Angius
Angius4mo ago
That's also true, we're talking VS Code here and we should really be talking VS 2022
rigamortus
rigamortusOP4mo ago
arc length isnt right
No description
rigamortus
rigamortusOP4mo ago
it should print this
No description
rigamortus
rigamortusOP4mo ago
not bothering to check anything else but yk
No description
Angius
Angius4mo ago
I'd tell you to use the debugger to check, but... online compiler
rigamortus
rigamortusOP4mo ago
yup uhh
Angius
Angius4mo ago
My bet is it's because of the 360 Try 360.0
rigamortus
rigamortusOP4mo ago
mk also prints 0
Angius
Angius4mo ago
Also, Convert.ToInt32() will just throw an error if you give it something like 123.456, btw
rigamortus
rigamortusOP4mo ago
eh its fine i doubt my teacher will care
Servator
Servator4mo ago
How is your methods access variables ?
rigamortus
rigamortusOP4mo ago
im doing this btw
No description
Servator
Servator4mo ago
$codeblock
rigamortus
rigamortusOP4mo ago
so its arc length thats not working
Angius
Angius4mo 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
Servator4mo ago
Am i missing something?
The Father
The Father4mo ago
send the source doe code again
rigamortus
rigamortusOP4mo ago
mk
The Father
The Father4mo ago
whenever there's a problem and you make a change send the source code
rigamortus
rigamortusOP4mo 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
MODiX4mo 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.
rigamortus
rigamortusOP4mo 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
Angius4mo 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
rigamortus
rigamortusOP4mo ago
No description
rigamortus
rigamortusOP4mo ago
im seeing it.. its arc angle it thinks its 0 for some reason
Angius
Angius4mo ago
No description
Angius
Angius4mo 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
Servator4mo ago
That's what i was talking about :Sad:
rigamortus
rigamortusOP4mo ago
oooh. so do i fix that by putting it somewhere else..?
Angius
Angius4mo ago
You fix it by removing the double
The Father
The Father4mo ago
oh yeah
Angius
Angius4mo ago
So it assigns to the existing field instead of making a new variable
Servator
Servator4mo ago
No description
Servator
Servator4mo ago
It should output something like this
The Father
The Father4mo ago
also the convert is wrong
Angius
Angius4mo ago
No description
Angius
Angius4mo ago
One works, the other does not
The Father
The Father4mo ago
do Convert.ToDouble
Angius
Angius4mo ago
Take note of the difference
rigamortus
rigamortusOP4mo ago
mk
The Father
The Father4mo ago
replace both of them
Angius
Angius4mo ago
It will be cast to double anyway
The Father
The Father4mo ago
when it converts it to an int it just rounds it
Angius
Angius4mo ago
And if anything, you should just get rid of Convert and use double.Parse()
rigamortus
rigamortusOP4mo ago
will do
Angius
Angius4mo ago
double.TryParse() ideally, but we're not there yet
rigamortus
rigamortusOP4mo ago
No description
rigamortus
rigamortusOP4mo ago
this might be the compiler im using but idk
The Father
The Father4mo ago
ToDouble
Angius
Angius4mo ago
No such thing as Double32 type Yeah
The Father
The Father4mo ago
double is just a 64 bit float
rigamortus
rigamortusOP4mo ago
ahh
The Father
The Father4mo ago
float is 32 bit
Angius
Angius4mo ago
Convert.ToDouble() (eugh. yuck, bad) double.Parse() (eh, sure, will do) Either of those works
rigamortus
rigamortusOP4mo ago
SUCCESS!! you're all Godsends now I'm going to sleep before I actually die
No description
The Father
The Father4mo ago
ez
rigamortus
rigamortusOP4mo ago
thank you for your time.
The Father
The Father4mo ago
np why is parse better i know why TryParse is but no Parse
Angius
Angius4mo ago
Convert will take a null and gladly treat it as a 0
MODiX
MODiX4mo 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 Father4mo ago
hm
MODiX
MODiX4mo 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
Angius4mo 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 Father4mo ago
ohh i didn't know that
Angius
Angius4mo ago
Well, properly-ish
The Father
The Father4mo ago
because the null terminator?
Angius
Angius4mo 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 Father4mo ago
hm
rigamortus
rigamortusOP4mo 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
Angius4mo ago
Sure
rigamortus
rigamortusOP4mo ago
oh nvm i fixed it im actually learning 🥹
Angius
Angius4mo ago
'Ere you go1
rigamortus
rigamortusOP4mo ago
nope nvm
Angius
Angius4mo ago
:kekw:
rigamortus
rigamortusOP4mo ago
the C2F is just kinda excess but uh
No description
rigamortus
rigamortusOP4mo ago
for once my code isnt a muddlke
Angius
Angius4mo ago
Did you perhaps mean to use else if? Also, use braces, they make things cleaner This ain't Python
rigamortus
rigamortusOP4mo ago
where do i put the... brackets?
No description
rigamortus
rigamortusOP4mo ago
they still confuse me but ill try
Angius
Angius4mo 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
}
rigamortus
rigamortusOP4mo ago
but like else if... what?
rigamortus
rigamortusOP4mo ago
No description
rigamortus
rigamortusOP4mo ago
ill use the braces ty
Angius
Angius4mo 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
Angius4mo ago
No description
Angius
Angius4mo ago
here
rigamortus
rigamortusOP4mo ago
oooh mk
rigamortus
rigamortusOP4mo ago
No description
rigamortus
rigamortusOP4mo ago
so like this? and i THINK thats how braces are
Angius
Angius4mo ago
yep
rigamortus
rigamortusOP4mo ago
i must be doing something wrong..
No description
Angius
Angius4mo ago
I see no errors
rigamortus
rigamortusOP4mo ago
it might be the code thingy im using
Angius
Angius4mo 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
rigamortus
rigamortusOP4mo ago
i was using dotnet fiddle but it just kinda crashes
Angius
Angius4mo ago
Right And Sharplab does not allow for user input So ig keep chugging along, using what you're using
rigamortus
rigamortusOP4mo ago
ill just submit this anyway and hope the teacher doesnt notice even though im literally only half done 😊
Angius
Angius4mo 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
rigamortus
rigamortusOP4mo 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
Angius4mo ago
% will be your friend And Math.Round() method
rigamortus
rigamortusOP4mo 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
Angius4mo ago
ye
rigamortus
rigamortusOP4mo ago
ok ill try that
Angius
Angius4mo ago
That works too, no need for %
rigamortus
rigamortusOP4mo ago
do I
No description
rigamortus
rigamortusOP4mo ago
REALLY have to separate them AGAIN
Angius
Angius4mo ago
No, why?
rigamortus
rigamortusOP4mo ago
well whys it saying they dont exist
Angius
Angius4mo ago
Yeah M2 = 7; is assigning the value of 7 to an existing M2
rigamortus
rigamortusOP4mo ago
ooooooooooh
Angius
Angius4mo ago
It has never actually been declared anywhere
rigamortus
rigamortusOP4mo ago
so. where do I declare it?
Angius
Angius4mo ago
So double M2 = ...
rigamortus
rigamortusOP4mo ago
should I just set it to 0 beforehand and let it update
Angius
Angius4mo 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
rigamortus
rigamortusOP4mo ago
ahhh mk
rigamortus
rigamortusOP4mo ago
sorry for bombarding you with problems that probably have easy solutions but
No description
rigamortus
rigamortusOP4mo ago
im so tired rn and i cant think straight i just need to get this do ne
rigamortus
rigamortusOP4mo ago
No description
rigamortus
rigamortusOP4mo ago
nvm fixed one it works thanks not bad considering I started learning C# 3 and a half hours ago
Angius
Angius4mo ago
Yeah lol
rigamortus
rigamortusOP4mo ago
and once again, nice tanya pfp real underrated show
Angius
Angius4mo ago
Oh yeah Can't wait for S2
rigamortus
rigamortusOP4mo ago
ITS COMING ?
Angius
Angius4mo 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?
rigamortus
rigamortusOP4mo ago
Surely not. I'm almost caught up on the manga and don't want to have to wait just yet..
Evyr
Evyr4mo 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
rigamortus
rigamortusOP4mo ago
So it’ll never round up to an odd number? Weird… Well I’ll keep that in consideration thanks
Evyr
Evyr4mo ago
iirc it's do to with rounding conventions in finance, or something like that
rigamortus
rigamortusOP4mo ago
Ah
Want results from more Discord servers?
Add your server