C#
C#

help

Root Question Message

cgxlm
cgxlm9/27/2022
Validation help

Need help with some simple validation
cgxlm
cgxlm9/27/2022
I realize whats wrong Im just not certain on how I fix it
if i enter a letter this line obviously cant convert it
double isales = Convert.ToDouble(sales);
How do i fix
Angius
Angius9/27/2022
$tryparse
Angius
Angius9/27/2022
This method was made for this explicit reason
Angius
Angius9/27/2022
It checks if your string can be converted into a given numeric type, and if so, converts it
cgxlm
cgxlm9/27/2022
im finding it a bit confusing to understand, where would i put this in my code and what would i need to change
Angius
Angius9/27/2022
You'd use it instead of your convert
cgxlm
cgxlm9/27/2022
Ahhh I see ive got it in now and its working thank you
cgxlm
cgxlm9/27/2022
cgxlm
cgxlm9/27/2022
How would I return overtime so I can use it down there
cgxlm
cgxlm9/27/2022
@85903769203642368
Angius
Angius9/27/2022
result is your parsed number
cgxlm
cgxlm9/27/2022
yeah but how do i still get it down to use there because changing overtime to result it still cant reach it
Angius
Angius9/27/2022
You're trying to use the variable in the outermost scope
Angius
Angius9/27/2022
So you need to declare it in the outermost scope
Angius
Angius9/27/2022
And instead of out var result in your tryparse, you can then use out thatOuterVariable
cgxlm
cgxlm9/27/2022
so do i put int overtimetotal = (overtime * 15);
inside of the parse one
Angius
Angius9/27/2022
Try and see
cgxlm
cgxlm9/27/2022
Angius
Angius9/27/2022
Well, that's not how you do it, then
Angius
Angius9/27/2022
$scopes
cgxlm
cgxlm9/27/2022
im confused so where abouts do i put it
Angius
Angius9/27/2022
You're trying to use the overtimetotal variable in the outermost scope
Angius
Angius9/27/2022
So you need to declare it in the outermost scope
Angius
Angius9/27/2022
int foo = 0;
{
  {
    {
      {
        foo += 10;
      }
    }
  }
}
Console.WriteLine(foo);
Angius
Angius9/27/2022
That's the tl;dr
cgxlm
cgxlm9/27/2022
ohhhhhhhh isee now thank you so much
taking me a while to wrap my head around it lol
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy