C# Int does not exist in current context when doing a basic math equasion

  • Thread starter Thread starter Kiddo 9000
  • Start date Start date
K

Kiddo 9000

Guest
Hello everyone.

I am quite new here so bare with me. I have made this simple script where the user selects a few items in some drop down boxes. The code checks to see what items were selected and returns a number to a specific int depending on what the result was. At the end, it will take these values and subtract them from 100 and display it on screen.

The problem: whenever i use the ints with the math equasion, it returns that my intergers "dont exist in the current context". Below is my code:


// Collect data from the IQ combo box
if (eq.SelectedText == "1 - 9")
{
int q = 110;
}
else if (eq.SelectedText == "10 - 19")
{
int q = 85;
}
else if (eq.SelectedText == "20 - 49")
{
int q = 50;
}
else if (eq.SelectedText == "50 - 99")
{
int q = 25;
}
else if (eq.SelectedText == "100 - 119")
{
int q = 5;
}
else if (eq.SelectedText == "120+")
{
int q = 10;
}


// Get the final result
int a = 100;
int r = a - q;

// Display the result
new Result().Show();


Error: The name 'q' does not exist in the current context (CS0103)

Can you help me out here? Thanks.

Continue reading...
 
Back
Top