✅ C sharp help
Hello, I'm working on a C# assignment and could use some help. The assignment involves creating a really easy code on building a "calendar"( when you click 1, the answer is monday etc). Specifically, I'm having trouble with if statements and the else if. If anyone is proficient in C# and would be willing to assist me, please send me a DM. Thank you!
50 Replies
it's good to start by posting relevant code
then use a switch statement, but relevant code is helpful
@donteventry143 you can use this as an example I just wrote.
Since its basic code the only "advanced" thing used is an Array.
@MayoWA @Preda
First of all, keep your code clean
I am really new to coding its my first time taking this calss
Press CTRL + A and then CTRL + K + D
class*
ok one sec
just did it
Send in again now
Im just not sure how to write a code so that if the user enters a number that is not 1-7 he will get error as an answer but if he does, the answer is today is a ___ ! without error message
So I won't do the work, I will just guide you.
Hover your cursor on the error
What is it saying?
no clue what this means
Don t mind that
i think the last 2 lines of code dont work
Show the error (which is marked with the red X)
would it make sense to use a if statement for what i am trying to do>
The code is 90% correct
I am struggling with the last part
All right so
I dont know how and if i can make an if statement for what i am trying to do
While using an IF statement
Nvm
So
can I do an if statement and make it like if x = to multiple things or that is what you are trying to say
like i can not do that
Do you know these 2 operator? "&&" and "||"
never seen those yet
So
&& stand for AND
So when you use it
oh got it
let me try it
You can have 2 conditions to be fulfied
Both have to be true
When using || it means OR
So you have 2 conditions and only one has to be fulfied
like this?
and I also had another question how would I write the else if weekdayREsult = to like anything else meaning nothing from 1 to 7
Will your weekdayResult be fullfied to 7 diffrent answers or just 1?
i am not sure if i understand your question
when my code runs you are just supposed to enter a number 1 through 7
to get a different day
and get error if we enter anythign else
I am trying to make you understand the logic behind it
I can also provide you the code
oh i found an error
But you won t learn anything from it
shouldnt it be day number in the before last line?
Hover your cursor on the red line to see detail
And tell me what is it telling
operator && can not be applied to strings
So that means you have to make your daynumber an INT
Instead of string
now that i changed it to int
Since your daynumber is a INT you can t use == with other types
Line 8
For example
but once i remove one of the =, it still dosent seem to work and can you check your dms? @Preda
Ok
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.