✅ 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
SG97
SG972y ago
it's good to start by posting relevant code
MayoWAA!
MayoWAA!2y ago
then use a switch statement, but relevant code is helpful
Preda
Preda2y ago
@donteventry143 you can use this as an example I just wrote.
int _calendarIndex;
string[] days = new string[] {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
Console.Write("Please give in day number: ");
_calendarIndex = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Selected day is: {days[--_calendarIndex]}");
Console.ReadKey();
int _calendarIndex;
string[] days = new string[] {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
Console.Write("Please give in day number: ");
_calendarIndex = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Selected day is: {days[--_calendarIndex]}");
Console.ReadKey();
Since its basic code the only "advanced" thing used is an Array.
donteventry143
donteventry143OP2y ago
donteventry143
donteventry143OP2y ago
@MayoWA @Preda
Preda
Preda2y ago
First of all, keep your code clean
donteventry143
donteventry143OP2y ago
I am really new to coding its my first time taking this calss
Preda
Preda2y ago
Press CTRL + A and then CTRL + K + D
donteventry143
donteventry143OP2y ago
class* ok one sec just did it
Preda
Preda2y ago
Send in again now
donteventry143
donteventry143OP2y ago
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
Preda
Preda2y ago
So I won't do the work, I will just guide you.
donteventry143
donteventry143OP2y ago
Preda
Preda2y ago
Hover your cursor on the error What is it saying?
donteventry143
donteventry143OP2y ago
donteventry143
donteventry143OP2y ago
no clue what this means
Preda
Preda2y ago
Don t mind that
donteventry143
donteventry143OP2y ago
i think the last 2 lines of code dont work
Preda
Preda2y ago
Show the error (which is marked with the red X)
donteventry143
donteventry143OP2y ago
would it make sense to use a if statement for what i am trying to do>
Preda
Preda2y ago
The code is 90% correct
donteventry143
donteventry143OP2y ago
I am struggling with the last part
donteventry143
donteventry143OP2y ago
Preda
Preda2y ago
All right so
donteventry143
donteventry143OP2y ago
I dont know how and if i can make an if statement for what i am trying to do
Preda
Preda2y ago
While using an IF statement Nvm So
donteventry143
donteventry143OP2y ago
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
Preda
Preda2y ago
Do you know these 2 operator? "&&" and "||"
donteventry143
donteventry143OP2y ago
never seen those yet
Preda
Preda2y ago
So && stand for AND So when you use it
donteventry143
donteventry143OP2y ago
oh got it let me try it
Preda
Preda2y ago
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
donteventry143
donteventry143OP2y ago
donteventry143
donteventry143OP2y ago
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
Preda
Preda2y ago
Will your weekdayResult be fullfied to 7 diffrent answers or just 1?
donteventry143
donteventry143OP2y ago
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
Preda
Preda2y ago
I am trying to make you understand the logic behind it I can also provide you the code
donteventry143
donteventry143OP2y ago
oh i found an error
Preda
Preda2y ago
But you won t learn anything from it
donteventry143
donteventry143OP2y ago
donteventry143
donteventry143OP2y ago
shouldnt it be day number in the before last line?
Preda
Preda2y ago
Hover your cursor on the red line to see detail And tell me what is it telling
donteventry143
donteventry143OP2y ago
operator && can not be applied to strings
Preda
Preda2y ago
So that means you have to make your daynumber an INT Instead of string
donteventry143
donteventry143OP2y ago
donteventry143
donteventry143OP2y ago
now that i changed it to int
Preda
Preda2y ago
Since your daynumber is a INT you can t use == with other types Line 8 For example
donteventry143
donteventry143OP2y ago
but once i remove one of the =, it still dosent seem to work and can you check your dms? @Preda
Preda
Preda2y ago
Ok
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server