❔ how do i use functions like for example "public static bool (int num = 0)"

Ddaniel12/27/2023
.
Ddaniel12/27/2023
my attempts so far consits of
Ddaniel12/27/2023
public static bool (int num = 0)
BBlyZe2/27/2023
You need to give the method a name
BBlyZe2/27/2023
public static bool MethodName(int num = 0)
Ddaniel12/27/2023
i tried
Ddaniel12/27/2023
public static bool op(int num = 0)
Ddaniel12/27/2023
its still red
BBlyZe2/27/2023
You need curly braces after
Ddaniel12/27/2023
"not all code paths return a vaule
BBlyZe2/27/2023
ahhh
Ddaniel12/27/2023
"
BBlyZe2/27/2023
you need to return a bool
BBlyZe2/27/2023
for example
BBlyZe2/27/2023
return true;
Ddaniel12/27/2023
public static bool op(int num = 0)
{
if (num > 3)
{
return "a";
}
}
BBlyZe2/27/2023
thats a string
BBlyZe2/27/2023
you can just
BBlyZe2/27/2023
return num > 3;
Ddaniel12/27/2023
what do you mean by that
BBlyZe2/27/2023
thats true if num is greater then 3 otherwise false
BBlyZe2/27/2023
public static bool op(int num = 0)
        {
           return num > 3;
        }
Ddaniel12/27/2023
you sure thats how it should be
Ddaniel12/27/2023
your not returning anything tho
Ddaniel12/27/2023
i need to return a massage
BBlyZe2/27/2023
i dont know what you want to archieve with this method
Ddaniel12/27/2023
let me send you the task
BBlyZe2/27/2023
then you have to change the return type
Ddaniel12/27/2023
one moment
Ddaniel12/27/2023
In a certain city it was determined that a building with more than 3 floors must have an elevator. Write an action
that you get a whole number greater than 0, representing the number of floors in the building. The operation will return the character 'a' if required
There must be an elevator in the building, otherwise the operation will return the character 'b.'
BBlyZe2/27/2023
Okay so you could do something like this:

public static char NeedsElevator(int floors)
{
    return floors > 3 ? 'a' : 'b';
}
Ddaniel12/27/2023
what does char mean
BBlyZe2/27/2023
char is a character
Ddaniel12/27/2023
do i need to use char for this
BBlyZe2/27/2023
you can also use string
BBlyZe2/27/2023
A char is a single character
BBlyZe2/27/2023
A string is a char array
PPobiega2/27/2023
I'd say use char, thats what it seems the task expects.
PPobiega2/27/2023
The operation will return the character 'a' if required
PPobiega2/27/2023
single quotes like that are only used for chars in C#
BBlyZe2/27/2023
Yeah then char
Ddaniel12/27/2023
return floors > 3 "a";
Ddaniel12/27/2023
this is not working
Ddaniel12/27/2023
its all red
PPobiega2/27/2023
"a" is a string, not a char
PPobiega2/27/2023
and also not a valid syntax
PPobiega2/27/2023
read BlyZe's code snippet again.
Ddaniel12/27/2023
it still dosent work
Ddaniel12/27/2023
why cant i use bool with it
PPobiega2/27/2023
what is a bool?
PPobiega2/27/2023
what values can a bool represent?
Ddaniel12/27/2023
i dont know
PPobiega2/27/2023
then why do you want to use a bool?
Ddaniel12/27/2023
but char is not working ethir
PPobiega2/27/2023
yes it is, if you write it correctly
MMODiX2/27/2023
PPobiega2/27/2023
this will 100% work just fine
Ddaniel12/27/2023
you sure my teacher will accept this
Ddaniel12/27/2023
she taught us to use bool and stuff
PPobiega2/27/2023
The task description clearly states that the method should return a char
PPobiega2/27/2023
but you do you
PPobiega2/27/2023
and absolutely do not copypaste the code Blyze sent
PPobiega2/27/2023
it will be more than obvious that you did not write it
PPobiega2/27/2023
Image
PPobiega2/27/2023
You don't really seem to be wanting to learn, only cheat on your homework?
Ddaniel12/27/2023
i have an exam tomrow
Ddaniel12/27/2023
this homework is not graded its just that if you cant to do the home work you probably fail the exam
Ddaniel12/27/2023
its 10 pm right now
PPobiega2/27/2023
Programming isn't really something you learn in a single evening, just saying.
Ddaniel12/27/2023
i know
Ddaniel12/27/2023
i havent done it for three months beacuse our teacher got into a car accidents and we were bombered with exams on every single other subject
AAngius2/27/2023
Well, the truth is, that regardless of that you can't learn programming if you only do it during class
Ddaniel12/27/2023
my 11th grade class is harder compared to other 11th grade classes in my country/ school
AAngius2/27/2023
2x45 minutes a week or however much is nothing
Ddaniel12/27/2023
i know
Ddaniel12/27/2023
thats why i am sitting here
AAngius2/27/2023
A day before exam
AAngius2/27/2023
Well, it's better than nothing I guess
AAngius2/27/2023
That said, you can easily worsen this code to school levels by using an if-else instead of the ternary
AAngius2/27/2023
public static string NeedsElevator(int floors)
{
    if (floors > 3)
    {
        return "There is more than three floors";
    }
    else
    {
        return "There is no more than three floors";
    }
}
Ddaniel12/27/2023
i could have studied yestarday but i had an exam yesterday in maths and it does sound like an excuse beacuse it is but i decided that beacuse i handeled that math exam so well i deserved to only study one day before the exam
TTvde12/27/2023
you should follow $helloworld
TTvde12/27/2023
I think it's very valuable
AAccord2/28/2023
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.