C
C#•8mo ago
rigger

āœ… need some help making a program

buuuuuuuuuuut im getting errors idk how to fix
No description
105 Replies
rigger
riggerOP•8mo ago
No description
rigger
riggerOP•8mo ago
changed it slightly
No description
Buddy
Buddy•8mo ago
How do you set the value of a variable? and how do you check if a value is equals to another value?
rigger
riggerOP•8mo ago
you just.. use =? ==..? im trying to get it to return false if the email doesnt have a @ and a .
Buddy
Buddy•8mo ago
Correct and check your code
rigger
riggerOP•8mo ago
ok
Buddy
Buddy•8mo ago
Read it out for yourself
Buddy
Buddy•8mo ago
if and switch statements - select a code path to execute - C# refer...
The if and switch statements provide branching logic in C#. You use if, else and switch` to choose the path your program follows.
rigger
riggerOP•8mo ago
but apparently..
No description
Buddy
Buddy•8mo ago
compare your if statement to what you wrote earlier Setting the value versus comparing a value
rigger
riggerOP•8mo ago
all i did was add a space to else if and change the = to ==
No description
Buddy
Buddy•8mo ago
And one more thing. Compare the example given in the microsoft documentation Last thing You have a character in your code that does not exist in the example
rigger
riggerOP•8mo ago
im ngl i dont understand the documentation at all i leant c# in 3 hours for school the basic basics ofc
Buddy
Buddy•8mo ago
if (char.IsUpper(ch))
{
Console.WriteLine($"An uppercase letter: {ch}");
}
else if (char.IsLower(ch))
{
Console.WriteLine($"A lowercase letter: {ch}");
}
else if (char.IsDigit(ch))
{
Console.WriteLine($"A digit: {ch}");
}
else
{
Console.WriteLine($"Not alphanumeric character: {ch}");
}
if (char.IsUpper(ch))
{
Console.WriteLine($"An uppercase letter: {ch}");
}
else if (char.IsLower(ch))
{
Console.WriteLine($"A lowercase letter: {ch}");
}
else if (char.IsDigit(ch))
{
Console.WriteLine($"A digit: {ch}");
}
else
{
Console.WriteLine($"Not alphanumeric character: {ch}");
}
Do you see any semicolons in the if-statement?
rigger
riggerOP•8mo ago
nope huh
Buddy
Buddy•8mo ago
Now, do you see any in yours?
rigger
riggerOP•8mo ago
well yeah but if i get rid of it
rigger
riggerOP•8mo ago
No description
rigger
riggerOP•8mo ago
it tells me to add it back
Buddy
Buddy•8mo ago
Please show the code
rigger
riggerOP•8mo ago
No description
Buddy
Buddy•8mo ago
variables cannot have a space in them
No description
rigger
riggerOP•8mo ago
oh oops
rigger
riggerOP•8mo ago
yeah.. idk if i can cope with this
No description
Buddy
Buddy•8mo ago
What exactly do you want to make?
rigger
riggerOP•8mo ago
i want to input text and check to see if it has at least 1 @ and 1 . if it doesnt have both then it tells you your email is invalid
Buddy
Buddy•8mo ago
Name your class Program change main to Main with a capital M, and remove all the parameters and put string[] args instead. Unless you have the ability to use top-level statements that's what you have to do.
rigger
riggerOP•8mo ago
mkay
Buddy
Buddy•8mo ago
But I have no idea what the site requires.
rigger
riggerOP•8mo ago
idk either i just cant use vscode so im stuck with this random compiler since vscode refuses to run
Buddy
Buddy•8mo ago
Did you follow this $vscode ?
MODiX
MODiX•8mo ago
Follow the instructions here on getting started with DevKit for C# in VSCode: https://code.visualstudio.com/docs/csharp/get-started
Get started with C# and .NET in Visual Studio Code
Getting Started with C# and .NET Development in Visual Studio Code
rigger
riggerOP•8mo ago
yup doesnt work
Buddy
Buddy•8mo ago
It might be easier to use Visual Studio Community 2022 VSCode is not for beginners And is not the same program as Visual Studio Community VS is an IDE whereas VSCode is not. meaning VS will install everything you need.
rigger
riggerOP•8mo ago
i tried using vs 2022 also didnt work i can retry though
Buddy
Buddy•8mo ago
define didn't work
rigger
riggerOP•8mo ago
like i tried running some program and it gave me errors not related to the program at all that i didnt understand i asked for help
Buddy
Buddy•8mo ago
any examples?
rigger
riggerOP•8mo ago
one second
rigger
riggerOP•8mo ago
No description
rigger
riggerOP•8mo ago
just didnt wanna work in vs 2022 but it worked on this random compiler ill reinstall vs 2022 but idk if i can get it to work
Buddy
Buddy•8mo ago
$newproject
MODiX
MODiX•8mo ago
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework. .NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended. https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
Buddy
Buddy•8mo ago
Make sure you use .NET (and not .NET Framework) Not that it has anything to do with the error. and worst case scenario you might just need to reinstall .NET
rigger
riggerOP•8mo ago
ive installed it 3 times literally 64 bit and 82(or 84 idk) bit
Buddy
Buddy•8mo ago
I can't see any errors with that code. Did you copy paste it?
rigger
riggerOP•8mo ago
yeah copy pasted 1 to 1
Buddy
Buddy•8mo ago
Then that might be it You could've accidentally pasted an invisible character And site maybe filters those out.
rigger
riggerOP•8mo ago
ok im signing into vs2022
rigger
riggerOP•8mo ago
i assume its this
No description
Buddy
Buddy•8mo ago
Make sure you do not open a folder as C# is project based and not file based
rigger
riggerOP•8mo ago
oh
Buddy
Buddy•8mo ago
so please go through the project wizard by pressing new project
rigger
riggerOP•8mo ago
?
No description
Buddy
Buddy•8mo ago
You must install the .net desktop development workload you can find it by running Visual Studio Installer and pressing modify There should be an app installed when you install Visual Studio, so you can just search for it
Buddy
Buddy•8mo ago
This should be checked
No description
rigger
riggerOP•8mo ago
alright
Buddy
Buddy•8mo ago
for you it's called .NET desktop development I don't have visual studio installed so it's called so for me because I only have the build tools (without the IDE).
rigger
riggerOP•8mo ago
im downloading it at m
Buddy
Buddy•8mo ago
Sweet!
Buddy
Buddy•8mo ago
After it's installed you should see a bunch of templates to your right. Here:
No description
Buddy
Buddy•8mo ago
Then you create a Console Application project and you'll have a template ready to go
rigger
riggerOP•8mo ago
this framework?
No description
Buddy
Buddy•8mo ago
That runtime, correct. Remember what I said before about top-level statements?
rigger
riggerOP•8mo ago
yeah using string [] args
Buddy
Buddy•8mo ago
This time you don't have to do so.
Buddy
Buddy•8mo ago
Left side is your code; right side is what the compiler spits out (meaning not something you have to write). So you can forget about the entry-point
rigger
riggerOP•8mo ago
oooh
Buddy
Buddy•8mo ago
That's what top-level statements does. Note that it is only for one file (the entry-point)
rigger
riggerOP•8mo ago
ok i wanna ask something though see how i kinda need to check if @ is entered right is IndexOf the right way to do that?
rigger
riggerOP•8mo ago
cause these r the errors im getting
No description
Buddy
Buddy•8mo ago
It's definitely a fast way of doing so, yes. You can however optimize it by instead declaring @ as a char meaning a single character you can do so like this
char at = '@';
char at = '@';
those single quotations means a character
rigger
riggerOP•8mo ago
ah mk ok so if i make Isearch a bool itll return false if @ isnt entered right?
rigger
riggerOP•8mo ago
No description
rigger
riggerOP•8mo ago
here
Buddy
Buddy•8mo ago
Oh, yeah. IndexOf returns the index of where the character was found I suggest reading the documentation of IndexOf https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof?view=net-8.0 Specifically this
Reports the zero-based index of the first occurrence of a specified Unicode character or string within this instance. The method returns -1 if the character or string is not found in this instance.
The latter part
rigger
riggerOP•8mo ago
so itll return -1 if its not found alright
Buddy
Buddy•8mo ago
Correct
rigger
riggerOP•8mo ago
ill just check to see if -1 is returned then
Buddy
Buddy•8mo ago
Correct
rigger
riggerOP•8mo ago
i can do that by.... doing if Isearch == -1 right?
Buddy
Buddy•8mo ago
First you must change your ISearch's to an integer but yes, and that means it has not been found in the text
rigger
riggerOP•8mo ago
done
rigger
riggerOP•8mo ago
No description
rigger
riggerOP•8mo ago
getting a lot of red lines thats perfectly fine thats what I want
Buddy
Buddy•8mo ago
You cannot declare variables multiple times check your code again
rigger
riggerOP•8mo ago
oops i thought you could ok apparently i cant use or thats different from python
rigger
riggerOP•8mo ago
No description
rigger
riggerOP•8mo ago
so && is or thats what im getting
Buddy
Buddy•8mo ago
Read again
rigger
riggerOP•8mo ago
or is it ||??
Buddy
Buddy•8mo ago
Yes, || is OR
rigger
riggerOP•8mo ago
oh ok thats kinda cryptic
Buddy
Buddy•8mo ago
Remember what I mentioned earlier, the semicolon
rigger
riggerOP•8mo ago
...
No description
rigger
riggerOP•8mo ago
OH right
rigger
riggerOP•8mo ago
now..
No description
Buddy
Buddy•8mo ago
if you want to combine them, it must be in a single if (foo == true || bar == false) { .. } and that means IF foo is true OR bar is false THEN (pseudocode)
rigger
riggerOP•8mo ago
ah i see IT WORKS OH MY DAYS IT WORKS YOURE A GODSEND
Buddy
Buddy•8mo ago
Amazing! That's all I can help you for today. Good luck on your journey! šŸ‘‹
rigger
riggerOP•8mo ago
THANK YOU šŸ™
Buddy
Buddy•8mo ago
Anytime. :catpog: $close
MODiX
MODiX•8mo ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?