C
C#ā€¢4mo ago
rigamortus

āœ… need some help making a program

buuuuuuuuuuut im getting errors idk how to fix
No description
105 Replies
rigamortus
rigamortusOPā€¢4mo ago
No description
rigamortus
rigamortusOPā€¢4mo ago
changed it slightly
No description
Buddy
Buddyā€¢4mo ago
How do you set the value of a variable? and how do you check if a value is equals to another value?
rigamortus
rigamortusOPā€¢4mo ago
you just.. use =? ==..? im trying to get it to return false if the email doesnt have a @ and a .
Buddy
Buddyā€¢4mo ago
Correct and check your code
rigamortus
rigamortusOPā€¢4mo ago
ok
Buddy
Buddyā€¢4mo ago
Read it out for yourself
Buddy
Buddyā€¢4mo 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.
rigamortus
rigamortusOPā€¢4mo ago
but apparently..
No description
Buddy
Buddyā€¢4mo ago
compare your if statement to what you wrote earlier Setting the value versus comparing a value
rigamortus
rigamortusOPā€¢4mo ago
all i did was add a space to else if and change the = to ==
No description
Buddy
Buddyā€¢4mo 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
rigamortus
rigamortusOPā€¢4mo ago
im ngl i dont understand the documentation at all i leant c# in 3 hours for school the basic basics ofc
Buddy
Buddyā€¢4mo 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?
rigamortus
rigamortusOPā€¢4mo ago
nope huh
Buddy
Buddyā€¢4mo ago
Now, do you see any in yours?
rigamortus
rigamortusOPā€¢4mo ago
well yeah but if i get rid of it
rigamortus
rigamortusOPā€¢4mo ago
No description
rigamortus
rigamortusOPā€¢4mo ago
it tells me to add it back
Buddy
Buddyā€¢4mo ago
Please show the code
rigamortus
rigamortusOPā€¢4mo ago
No description
Buddy
Buddyā€¢4mo ago
variables cannot have a space in them
No description
rigamortus
rigamortusOPā€¢4mo ago
oh oops
rigamortus
rigamortusOPā€¢4mo ago
yeah.. idk if i can cope with this
No description
Buddy
Buddyā€¢4mo ago
What exactly do you want to make?
rigamortus
rigamortusOPā€¢4mo 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ā€¢4mo 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.
rigamortus
rigamortusOPā€¢4mo ago
mkay
Buddy
Buddyā€¢4mo ago
But I have no idea what the site requires.
rigamortus
rigamortusOPā€¢4mo ago
idk either i just cant use vscode so im stuck with this random compiler since vscode refuses to run
Buddy
Buddyā€¢4mo ago
Did you follow this $vscode ?
MODiX
MODiXā€¢4mo 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
rigamortus
rigamortusOPā€¢4mo ago
yup doesnt work
Buddy
Buddyā€¢4mo 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.
rigamortus
rigamortusOPā€¢4mo ago
i tried using vs 2022 also didnt work i can retry though
Buddy
Buddyā€¢4mo ago
define didn't work
rigamortus
rigamortusOPā€¢4mo 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ā€¢4mo ago
any examples?
rigamortus
rigamortusOPā€¢4mo ago
one second
rigamortus
rigamortusOPā€¢4mo ago
No description
rigamortus
rigamortusOPā€¢4mo 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ā€¢4mo ago
$newproject
MODiX
MODiXā€¢4mo 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ā€¢4mo 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
rigamortus
rigamortusOPā€¢4mo ago
ive installed it 3 times literally 64 bit and 82(or 84 idk) bit
Buddy
Buddyā€¢4mo ago
I can't see any errors with that code. Did you copy paste it?
rigamortus
rigamortusOPā€¢4mo ago
yeah copy pasted 1 to 1
Buddy
Buddyā€¢4mo ago
Then that might be it You could've accidentally pasted an invisible character And site maybe filters those out.
rigamortus
rigamortusOPā€¢4mo ago
ok im signing into vs2022
rigamortus
rigamortusOPā€¢4mo ago
i assume its this
No description
Buddy
Buddyā€¢4mo ago
Make sure you do not open a folder as C# is project based and not file based
rigamortus
rigamortusOPā€¢4mo ago
oh
Buddy
Buddyā€¢4mo ago
so please go through the project wizard by pressing new project
rigamortus
rigamortusOPā€¢4mo ago
?
No description
Buddy
Buddyā€¢4mo 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ā€¢4mo ago
This should be checked
No description
rigamortus
rigamortusOPā€¢4mo ago
alright
Buddy
Buddyā€¢4mo 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).
rigamortus
rigamortusOPā€¢4mo ago
im downloading it at m
Buddy
Buddyā€¢4mo ago
Sweet!
Buddy
Buddyā€¢4mo ago
After it's installed you should see a bunch of templates to your right. Here:
No description
Buddy
Buddyā€¢4mo ago
Then you create a Console Application project and you'll have a template ready to go
rigamortus
rigamortusOPā€¢4mo ago
this framework?
No description
Buddy
Buddyā€¢4mo ago
That runtime, correct. Remember what I said before about top-level statements?
rigamortus
rigamortusOPā€¢4mo ago
yeah using string [] args
Buddy
Buddyā€¢4mo ago
This time you don't have to do so.
Buddy
Buddyā€¢4mo 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
rigamortus
rigamortusOPā€¢4mo ago
oooh
Buddy
Buddyā€¢4mo ago
That's what top-level statements does. Note that it is only for one file (the entry-point)
rigamortus
rigamortusOPā€¢4mo 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?
rigamortus
rigamortusOPā€¢4mo ago
cause these r the errors im getting
No description
Buddy
Buddyā€¢4mo 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
rigamortus
rigamortusOPā€¢4mo ago
ah mk ok so if i make Isearch a bool itll return false if @ isnt entered right?
rigamortus
rigamortusOPā€¢4mo ago
No description
rigamortus
rigamortusOPā€¢4mo ago
here
Buddy
Buddyā€¢4mo 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
rigamortus
rigamortusOPā€¢4mo ago
so itll return -1 if its not found alright
Buddy
Buddyā€¢4mo ago
Correct
rigamortus
rigamortusOPā€¢4mo ago
ill just check to see if -1 is returned then
Buddy
Buddyā€¢4mo ago
Correct
rigamortus
rigamortusOPā€¢4mo ago
i can do that by.... doing if Isearch == -1 right?
Buddy
Buddyā€¢4mo ago
First you must change your ISearch's to an integer but yes, and that means it has not been found in the text
rigamortus
rigamortusOPā€¢4mo ago
done
rigamortus
rigamortusOPā€¢4mo ago
No description
rigamortus
rigamortusOPā€¢4mo ago
getting a lot of red lines thats perfectly fine thats what I want
Buddy
Buddyā€¢4mo ago
You cannot declare variables multiple times check your code again
rigamortus
rigamortusOPā€¢4mo ago
oops i thought you could ok apparently i cant use or thats different from python
rigamortus
rigamortusOPā€¢4mo ago
No description
rigamortus
rigamortusOPā€¢4mo ago
so && is or thats what im getting
Buddy
Buddyā€¢4mo ago
Read again
rigamortus
rigamortusOPā€¢4mo ago
or is it ||??
Buddy
Buddyā€¢4mo ago
Yes, || is OR
rigamortus
rigamortusOPā€¢4mo ago
oh ok thats kinda cryptic
Buddy
Buddyā€¢4mo ago
Remember what I mentioned earlier, the semicolon
rigamortus
rigamortusOPā€¢4mo ago
...
No description
rigamortus
rigamortusOPā€¢4mo ago
OH right
rigamortus
rigamortusOPā€¢4mo ago
now..
No description
Buddy
Buddyā€¢4mo 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)
rigamortus
rigamortusOPā€¢4mo ago
ah i see IT WORKS OH MY DAYS IT WORKS YOURE A GODSEND
Buddy
Buddyā€¢4mo ago
Amazing! That's all I can help you for today. Good luck on your journey! šŸ‘‹
rigamortus
rigamortusOPā€¢4mo ago
THANK YOU šŸ™
Buddy
Buddyā€¢4mo ago
Anytime. :catpog: $close
MODiX
MODiXā€¢4mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server