C
C#2y ago
Rikk

✅ Need help regarding variables and class.

Need help regarding variables and class.
170 Replies
Rikk
RikkOP2y ago
Rikk
RikkOP2y ago
Is it possible to use the variable operation1 from the Main method in this other method?
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
yes. you don't show where you call addition but you could just call Addition and pass it the variables you need. you'd need to update the function definition to take those variables as well Addition(int x, int y)
cap5lut
cap5lut2y ago
ususally u would pass it as parameter
Rikk
RikkOP2y ago
so I can do that every time I want to pass a variable on?
Rikk
RikkOP2y ago
Like this?
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
yeah you can pass parameters around functions all you want. its a fundamental part of any (most) programming language
Rikk
RikkOP2y ago
Alright, got it, thanks. this is how to do it right? it seems to have worked
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
yes that syntax is correct.
cap5lut
cap5lut2y ago
u should rethink the Adttion method in a semantical way. what is an addition? (it takes 2 operands and sums them, then returns a value) thus ur method should take 2 parameters and return a value based on that
Rikk
RikkOP2y ago
Yeah, I can do it in the if/else way but I am trying to learn the methods
cap5lut
cap5lut2y ago
the Op input (i assume it stands for operator) would then be data to decide which method to call, so u have one method for each possible operation, and decide which to call based on that
Rikk
RikkOP2y ago
yes it is operator Yes that is exactly what I have in mind
cap5lut
cap5lut2y ago
lets start with the methods then, and forget about user input for now ;p
Rikk
RikkOP2y ago
If the Op is +, Addition(); if the Op is * and vice versa
cap5lut
cap5lut2y ago
from that info, how would u write the Addition method in $code?
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Rikk
RikkOP2y ago
static void Addition(int operation1, int operation2, int Op)
{
int Res1 = (operation1 + operation2);
Console.Write("Result:" + Res1);


}
static void Addition(int operation1, int operation2, int Op)
{
int Res1 = (operation1 + operation2);
Console.Write("Result:" + Res1);


}
I am thinking of this
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
but what if you want to do something with that number after adding it
Rikk
RikkOP2y ago
I dont think int Op needs to be transferred
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
it does not, and operator also wouldn't be an int
Rikk
RikkOP2y ago
I haven't thought about it lol Oh
cap5lut
cap5lut2y ago
this method hasissues in my opinion: 1) its called Addition so its very clear what it should do, thus the Op parameter should be needed, right? 2) the method does something with the calculated value, thats not its job. its job is to calculate the value and return it
Rikk
RikkOP2y ago
wait what does this mean?
cap5lut
cap5lut2y ago
imagine having this line of code: int someValue = Addition(1, 2);,l there u would expect that someValue is 3 afterwards u also would not expect that something is printed to the console at that time well, '"+"' is a string, basically zero or more characters (basically some text), Op is an integer value. its simply not defined how to compare these different types
Rikk
RikkOP2y ago
I want it so that in the main method, if the Op = + or * or anything else, it will perform that specific method applied to it that was my initial conception but it seems to be failing miserably
cap5lut
cap5lut2y ago
u need to think about how to split ur task into minor task 1) take input 2) process the input 3) display the results
Rikk
RikkOP2y ago
So how do I fix that
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
what type is Op right now
Rikk
RikkOP2y ago
its an int
cap5lut
cap5lut2y ago
thats the order in which ur program will execute, but from the programming side, u should first think about which methods u should write and how to write them (afterwards we talk about handling the user input)
Rikk
RikkOP2y ago
Rikk
RikkOP2y ago
getting errors here so you're suggesting I write the other methods for all the operators first?
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
you can't really compare a number to a string. because they are just completely different. What type do you think Op should be?
cap5lut
cap5lut2y ago
basically yes, but lets stick to Addition for now
Rikk
RikkOP2y ago
String
cap5lut
cap5lut2y ago
as earlier explained, that method should only have one job. doing the addition and returning its value do u know how to return a value from a method? (i do not mean printing it)
Rikk
RikkOP2y ago
return; ?
cap5lut
cap5lut2y ago
the return keyword is use yes return; only works for methods that return nothing (void), but thats not what ya want right? u want to return the sum of these 2 operands, so u want to return an int
Rikk
RikkOP2y ago
Ohh I get it now
cap5lut
cap5lut2y ago
then show the code ;p
Rikk
RikkOP2y ago
So I should get rid of the Console.Writeline from the Addition method, return the int to the Main method, and show the result there?
cap5lut
cap5lut2y ago
yep
Rikk
RikkOP2y ago
how do I return the integer? :P
cap5lut
cap5lut2y ago
first of all u have to rewrite the method header static void Addition(...) -> the void says there is no return value, so if u change that to another type, u declare that the method returns that type (in ur case an int)
Rikk
RikkOP2y ago
static int Addition(int operation1, int operation2)
static int Addition(int operation1, int operation2)
this?
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
yes
cap5lut
cap5lut2y ago
yep
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
now you have to return an int
Rikk
RikkOP2y ago
I get this
cap5lut
cap5lut2y ago
return; which value do u return here? none ;p
Rikk
RikkOP2y ago
the Result Res1 return (Res1);
cap5lut
cap5lut2y ago
yep u dont have to use the parenthesis tho
Rikk
RikkOP2y ago
Oh okay
cap5lut
cap5lut2y ago
return Res1; would be enough and totally get of the Console.Write() call there
Rikk
RikkOP2y ago
Console.Write("Result:" + Res1); So this should work in the main method now? yeah I did it
cap5lut
cap5lut2y ago
well, dont think that the Res1 in the Addition method and in the Main method are the same variables they just happen to have the same name
Rikk
RikkOP2y ago
cap5lut
cap5lut2y ago
the method takes 2 integers as parameters and returns 1 integer as result
Rikk
RikkOP2y ago
Yeah
cap5lut
cap5lut2y ago
so int result = Addition(1, 29); would be a way to call the method and storing its result in result
Rikk
RikkOP2y ago
what's the 1, 29?
cap5lut
cap5lut2y ago
afterwards u can use Console.Write("Result:" result); to print out the result just example values for the parameters
Rikk
RikkOP2y ago
do you mean something like this?
cap5lut
cap5lut2y ago
these can either be values (as shown already) or variables of the type int
Rikk
RikkOP2y ago
yeah they are variables the operands, the user inputs them
cap5lut
cap5lut2y ago
yeah, i simplified it for the explanation ;p
int a = 1;
int b = 29;
int result = Addition(a, b);
int a = 1;
int b = 29;
int result = Addition(a, b);
would basically the same
Rikk
RikkOP2y ago
I am confused, shouldnt this work? beucase in the Addition method I already assigned the sum of the operands to the variable Res1 and returned it
cap5lut
cap5lut2y ago
now u would just have to replace the numbers with int.Parse(...) to get the actual user input for the operands
Rikk
RikkOP2y ago
yes I've done it
class Program
{

static void Main(string[] args)
{
Console.WriteLine("Enter the problem.\nInclude spaces in between for correct functioning.");
string Problem = Console.ReadLine();

string[] C = Problem.Split(' ');
int operation1 = int.Parse(C[0]);
int Op = int.Parse(C[1]);
int operation2 = int.Parse(C[2]);

if (Op == +)
{
int result = Addition(Res1);
Console.Write("Result:" + result);

}


}

static int Addition(int operation1, int operation2)
{
int Res1 = (operation1 + operation2);
return Res1;
}
static int Product(int operation1, int operation2)
{
int Res2 = (operation1 * operation2);
Console.Write("Result:" + Res2);
return Res2;

}



}
class Program
{

static void Main(string[] args)
{
Console.WriteLine("Enter the problem.\nInclude spaces in between for correct functioning.");
string Problem = Console.ReadLine();

string[] C = Problem.Split(' ');
int operation1 = int.Parse(C[0]);
int Op = int.Parse(C[1]);
int operation2 = int.Parse(C[2]);

if (Op == +)
{
int result = Addition(Res1);
Console.Write("Result:" + result);

}


}

static int Addition(int operation1, int operation2)
{
int Res1 = (operation1 + operation2);
return Res1;
}
static int Product(int operation1, int operation2)
{
int Res2 = (operation1 * operation2);
Console.Write("Result:" + Res2);
return Res2;

}



}
this is the code
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
but what value do those numbers actually have? you haven't told the function yet
cap5lut
cap5lut2y ago
the Res1 in that method is another variable that just happens to have the same name
Rikk
RikkOP2y ago
they are variables that will be gathered from ReadLine
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
yes, but you never told the function that, you gave it one parameter Res1 thats not defined in that scope. A variable created in a function doesn't exist outside that function unless you return it and store it
cap5lut
cap5lut2y ago
these are so called local variables. local as in that they only exist in their scope (basically in the stuff between the { and } )
Rikk
RikkOP2y ago
Okay so it seems like I have returned it, but haven't stored it is that it?
cap5lut
cap5lut2y ago
int result = Addition(Res1); u stored it in result
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
int result = Addition(Res1); this is you storing the result, but addition takes two numbers and adds them, you need to give it two numbers Addition(x, y)
Rikk
RikkOP2y ago
yeah the private class and public class?
cap5lut
cap5lut2y ago
tho u did not pass the correct parameters
Rikk
RikkOP2y ago
Rikk
RikkOP2y ago
Is this what you mean?
cap5lut
cap5lut2y ago
public and private is something else, forget about it for now thats correct
Rikk
RikkOP2y ago
Oh I got it, the method doesnt store in the variables, but just the function it's like a recipe book
cap5lut
cap5lut2y ago
sorta, eye *yes
Rikk
RikkOP2y ago
so in the main class, I use the variables as ingredients and use the methods as the recipe book to quickly cook it
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
that is correct, now Op is a string, and + is the addition symbol, you need to compare Op to the string "+" as thats what the user will be inputting
Rikk
RikkOP2y ago
quite literally
cap5lut
cap5lut2y ago
yep, but one addition: its not the main class but the main method ;p
Rikk
RikkOP2y ago
yeah I miscalled it Wdym compare?
cap5lut
cap5lut2y ago
ill quickly smoke outdoors and return for the rest of the stuff (will take ~5min)
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
Op == "+" compare
Rikk
RikkOP2y ago
Alright, you have helped a lot, thank you! I am grateful if (Op == "+") so like this?
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
yes
Rikk
RikkOP2y ago
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
What type do you have Op set to?
Rikk
RikkOP2y ago
int
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
and what should it be its not a number, thats for sure
Rikk
RikkOP2y ago
string
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
ints are only numbers yeah
Rikk
RikkOP2y ago
but if I do that it messes up my int.parse I cant split the operands and operator then
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
maybe you shouldn't Int.Parse that one because its not an int you know ahead of time its never going to be an int so just don't try parsing an int out of it
Rikk
RikkOP2y ago
Rikk
RikkOP2y ago
Oh
Rikk
RikkOP2y ago
will this work?
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
parenthesis not needed, but yes
Rikk
RikkOP2y ago
I think it should, it will still take in the array okay let me give it a try It works!!
cap5lut
cap5lut2y ago
back from smoking ;p so whats ur current code?
Rikk
RikkOP2y ago
I added the 4 basic operators it works perfectly thanks a lot both of you! I am really grateful
cap5lut
cap5lut2y ago
glad to serve ya o7
Rikk
RikkOP2y ago
{
class Program
{

static void Main(string[] args)
{
Console.WriteLine("Enter the problem.\nInclude spaces in between for correct functioning.");
string Problem = Console.ReadLine();

string[] C = Problem.Split(' ');
int operation1 = int.Parse(C[0]);
string Op = (C[1]);
int operation2 = int.Parse(C[2]);

if (Op == "+")
{
int result = Addition(operation1, operation2);
Console.Write("Result:" + result);

}

else if (Op == "*")
{
int result1 = Product(operation1, operation2);
Console.Write("Result" + result1);

}
else if (Op == "-")
{
int result2 = Subtraction(operation1, operation2);
Console.Write("Result" + result2);

}
else if (Op == "/")
{
int result3 = Division(operation1, operation2);
Console.Write("Result" + result3);

}


static int Addition(int operation1, int operation2)
{
int Res1 = (operation1 + operation2);
return Res1;
}
static int Product(int operation1, int operation2)
{
int Res2 = (operation1 * operation2);
return Res2;

}
static int Subtraction(int operation1, int operation2)
{
int Res3 = (operation1 - operation2);
return Res3;

}
static int Division(int operation1, int operation2)
{
int Res4 = (operation1 / operation2);
return Res4;

}

}
}
}
{
class Program
{

static void Main(string[] args)
{
Console.WriteLine("Enter the problem.\nInclude spaces in between for correct functioning.");
string Problem = Console.ReadLine();

string[] C = Problem.Split(' ');
int operation1 = int.Parse(C[0]);
string Op = (C[1]);
int operation2 = int.Parse(C[2]);

if (Op == "+")
{
int result = Addition(operation1, operation2);
Console.Write("Result:" + result);

}

else if (Op == "*")
{
int result1 = Product(operation1, operation2);
Console.Write("Result" + result1);

}
else if (Op == "-")
{
int result2 = Subtraction(operation1, operation2);
Console.Write("Result" + result2);

}
else if (Op == "/")
{
int result3 = Division(operation1, operation2);
Console.Write("Result" + result3);

}


static int Addition(int operation1, int operation2)
{
int Res1 = (operation1 + operation2);
return Res1;
}
static int Product(int operation1, int operation2)
{
int Res2 = (operation1 * operation2);
return Res2;

}
static int Subtraction(int operation1, int operation2)
{
int Res3 = (operation1 - operation2);
return Res3;

}
static int Division(int operation1, int operation2)
{
int Res4 = (operation1 / operation2);
return Res4;

}

}
}
}
salute
cap5lut
cap5lut2y ago
i have some hints on that
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
you can use result for all of them btw.
Rikk
RikkOP2y ago
Oh
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
because they are all the same if statement only one of those would ever run
Rikk
RikkOP2y ago
oh correct I forgot
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
the operator can't be two different things
cap5lut
cap5lut2y ago
first of all, dont use these ResX variables in each (else) if branch
Rikk
RikkOP2y ago
I am stupid
cap5lut
cap5lut2y ago
int result;
if (blah)
{
result = 1; // just example code
}
else if (blah2)
{
result = 2;
}
int result;
if (blah)
{
result = 1; // just example code
}
else if (blah2)
{
result = 2;
}
Rikk
RikkOP2y ago
also I think I can just use Res for the methods too, right? or will it mess it up
cap5lut
cap5lut2y ago
that way u will have one variable that stores ur data
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
you could, but since you aren't doing anything else with the variable, i wouldn't even store it return operation1 + operation2
cap5lut
cap5lut2y ago
and after these if else stuff u can use result to further process it (like Console.WriteLine("Your result is" + result);)
Rikk
RikkOP2y ago
That would make it shorter, good idea yeah there is only 1 function so no need to store it
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
yeah as clear and concise as you can make it is best often shorter is better, but sometimes it makes it a lot harder to read
Rikk
RikkOP2y ago
So I can have one for all of them?
cap5lut
cap5lut2y ago
also in ur different methods for calculating (Addition and the others) u have these ResX variables they only exist in the method, so they all can have the same name
static int Addition(int a, int b)
{
int result = a + b;
return result;
}
static int Substraction(int a, int b)
{
int result = a - b;
return result;
}
static int Addition(int a, int b)
{
int result = a + b;
return result;
}
static int Substraction(int a, int b)
{
int result = a - b;
return result;
}
these are totally valid, and the result from Addition and the result from Substraction are completely different variables that only exist within their scopes/methods
Rikk
RikkOP2y ago
is this what you meant?
cap5lut
cap5lut2y ago
of course the return a + b; variant as LIVE suggested is valid as well and u dont even have to introduce a variable
Rikk
RikkOP2y ago
it cant find result though
cap5lut
cap5lut2y ago
almost variables exist in the scopes where they are declared
Rikk
RikkOP2y ago
what's the mistake
cap5lut
cap5lut2y ago
a scope is basically everything between the { and the }
Rikk
RikkOP2y ago
yeah
cap5lut
cap5lut2y ago
because u want result "outside" of the if/else if stuff, u need to declare it before that in the outer scope
Rikk
RikkOP2y ago
I hate dealing with them, it always messes up so I can declare it as 0?
cap5lut
cap5lut2y ago
int result;
if (...)
{
result = ...;
}
int result;
if (...)
{
result = ...;
}
Rikk
RikkOP2y ago
and that value will get updated in the if and elifs
cap5lut
cap5lut2y ago
(im too lazy to write it out, replace the ... with code xD) yep and then afterwards u can still use it for ur Console.WriteLine call
Rikk
RikkOP2y ago
Rikk
RikkOP2y ago
should I remove the int
cap5lut
cap5lut2y ago
yeah, u are trying to declare a variable again there. Type VariableName is a declaration (in ur case int result) but it already exists, so it complains
Rikk
RikkOP2y ago
I think that is it yeah correct I was just thinking that
cap5lut
cap5lut2y ago
u just want to use it there now, so just use the variable name result = ... (no int there)
Rikk
RikkOP2y ago
class Program
{

static void Main(string[] args)
{
Console.WriteLine("Enter the problem.\nInclude spaces in between for correct functioning.");
string Problem = Console.ReadLine();

string[] C = Problem.Split(' ');
int operation1 = int.Parse(C[0]);
string Op = (C[1]);
int operation2 = int.Parse(C[2]);
int result = 0;

if (Op == "+")
{
result = Addition(operation1, operation2);
}

else if (Op == "*")
{
result = Product(operation1, operation2);
}
else if (Op == "-")
{
result = Subtraction(operation1, operation2);
}
else if (Op == "/")
{
result = Division(operation1, operation2);
}

Console.WriteLine("Your Result is" + result);

static int Addition(int operation1, int operation2)
{
return (operation1 + operation2);
}
static int Product(int operation1, int operation2)
{
return (operation1 * operation2);
}
static int Subtraction(int operation1, int operation2)
{
return (operation1 - operation2);
}
static int Division(int operation1, int operation2)
{
return (operation1 / operation2);
}

}
}
}
class Program
{

static void Main(string[] args)
{
Console.WriteLine("Enter the problem.\nInclude spaces in between for correct functioning.");
string Problem = Console.ReadLine();

string[] C = Problem.Split(' ');
int operation1 = int.Parse(C[0]);
string Op = (C[1]);
int operation2 = int.Parse(C[2]);
int result = 0;

if (Op == "+")
{
result = Addition(operation1, operation2);
}

else if (Op == "*")
{
result = Product(operation1, operation2);
}
else if (Op == "-")
{
result = Subtraction(operation1, operation2);
}
else if (Op == "/")
{
result = Division(operation1, operation2);
}

Console.WriteLine("Your Result is" + result);

static int Addition(int operation1, int operation2)
{
return (operation1 + operation2);
}
static int Product(int operation1, int operation2)
{
return (operation1 * operation2);
}
static int Subtraction(int operation1, int operation2)
{
return (operation1 - operation2);
}
static int Division(int operation1, int operation2)
{
return (operation1 / operation2);
}

}
}
}
there we go it works perfectly too
cap5lut
cap5lut2y ago
that should be correct, but i still have 2 things to mention
Rikk
RikkOP2y ago
Hold on I'll be back in 10 mins
cap5lut
cap5lut2y ago
first of all: variables should always be camelCase (basically starting with lower letter (a instead of A), and only on word boundaries start with a higher letter) so op instead of op. actually the naming has more to it: Addition(int operation1, int operation2), these variables arent operations, but operands, so they should be called that additionally, because this is a common math thingy, its usually lhs and rhs (left/right hand side) and dont be lazy on names, op should be operation in this case
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
yeah thats an example where shorter also makes it worse code, because its less readable
cap5lut
cap5lut2y ago
the last thing: u defined the methods Addition and alike inside of Main, u should not do this, do it in the outer scope
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
another thing i'd add, what if you were to do "5 / 2" what answer would you get?
cap5lut
cap5lut2y ago
like
public class Program
{
static void Main()
{
...
}
static int Addition(...) ...
}
public class Program
{
static void Main()
{
...
}
static int Addition(...) ...
}
(currently just like variables, these methods only exist within the scope of the Main method, which is a bad design choice) there is ofc more to it, but thats far away from the beginner level ;p so all in all i would rename Problem to problem, C probably to something like component and the operationX to operandX (where X is the number) if u have adjusted that, please show ur code again ;p (there is more stuff but im not sure if im overexerting then)
Rikk
RikkOP2y ago
Okay, I got it yeah I wasn't sure what to name them so I just put some jibberish I'll have to use the % yeah I fixed it now
cap5lut
cap5lut2y ago
thats the point, always give it a meaningful name, even if its long. imagine more complex code u revisist afte 6-12 months, u would not understand a thing with weird naming ;P *cough*
Rikk
RikkOP2y ago
class Program
{

static void Main(string[] args)
{
Console.WriteLine("Enter the problem.\nInclude spaces in between for correct functioning.");
string Problem = Console.ReadLine();

string[] component = Problem.Split(' ');
int operand1 = int.Parse(component[0]);
string operation = (component[1]);
int operand2 = int.Parse(component[2]);
int result = 0;

if (operation == "+")
{
result = Addition(operand1, operand2);
}

else if (operation == "*")
{
result = Product(operand1, operand2);
}
else if (operation == "-")
{
result = Subtraction(operand1, operand2);
}
else if (operation == "/")
{
result = Division(operand1, operand2);
}

Console.WriteLine("Your Result is" + result);
}

static int Addition(int operand1, int operand2)
{
return (operand1 + operand2);
}
static int Product(int operand1, int operand2)
{
return (operand1 * operand2);
}
static int Subtraction(int operand1, int operand2)
{
return (operand1 - operand2);
}
static int Division(int operand1, int operand2)
{
return (operand1 / operand2);
}


}
}
class Program
{

static void Main(string[] args)
{
Console.WriteLine("Enter the problem.\nInclude spaces in between for correct functioning.");
string Problem = Console.ReadLine();

string[] component = Problem.Split(' ');
int operand1 = int.Parse(component[0]);
string operation = (component[1]);
int operand2 = int.Parse(component[2]);
int result = 0;

if (operation == "+")
{
result = Addition(operand1, operand2);
}

else if (operation == "*")
{
result = Product(operand1, operand2);
}
else if (operation == "-")
{
result = Subtraction(operand1, operand2);
}
else if (operation == "/")
{
result = Division(operand1, operand2);
}

Console.WriteLine("Your Result is" + result);
}

static int Addition(int operand1, int operand2)
{
return (operand1 + operand2);
}
static int Product(int operand1, int operand2)
{
return (operand1 * operand2);
}
static int Subtraction(int operand1, int operand2)
{
return (operand1 - operand2);
}
static int Division(int operand1, int operand2)
{
return (operand1 / operand2);
}


}
}
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
You could, that would allow you to stick with integers. But there are some different types that handle decimals better ( better said, they handle floating-point operations) there are 3: float, double, and decimal but for these purposes I would just start with float, its the smallest of the 3 and has the least amount of precision but its best practices to only use the types you need to use.
Rikk
RikkOP2y ago
Yeah I've used float in python before I guess it's similar here
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
yeah python just doesn't enforce typing so its a bit different
Rikk
RikkOP2y ago
float result = (operand1 / operand2); I hated how stupid it is to create an UI and executable
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
python is good to learn programming basics on, but overall its a worse language for actual programs. I like it for scripting and light repeatable tasks its also so much slower, even though it uses a lot of c
Rikk
RikkOP2y ago
Yeah true
Rikk
RikkOP2y ago
should I change all these integers to floats?
L-I-V-E-2DAY
L-I-V-E-2DAY2y ago
you could, it depends on what you want to support. If we are talking full calculator functionality it would have to be all floats, a calculator can handle 0.3 * 1.2 just fine.
Rikk
RikkOP2y ago
well it works now
Rikk
RikkOP2y ago
Well, gonna go get some sleep now. Thanks for the help guys, it means a lot learnt alot today!
cap5lut
cap5lut2y ago
u can do really pretty stuff with python, simply because most modules r c binaries instead of pure python
its also so much slower, even though it uses a lot of c
*nods* glad i could help o7 if ur questions here are answered please $close the thread to mark it as answered 😉
MODiX
MODiX2y ago
Use the /close command to mark a forum thread as answered
Rikk
RikkOP2y ago
HmmCouncilRTX5
MODiX
MODiX2y ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server