C
C#ā€¢3mo ago
'brella boy

āœ… need some help making a program

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