well ive declared a string called "res" in a function...then i made a while that has a if inside that has a switch inside...then i try to assign a value to "res" but it says it's out of scoop..*** is this? it should work! lolol!
Printable View
well ive declared a string called "res" in a function...then i made a while that has a if inside that has a switch inside...then i try to assign a value to "res" but it says it's out of scoop..*** is this? it should work! lolol!
omg my IDE gone insane..now it points error to any operator just like += , % etc..omg LOL
made build several times and still gave error..now after a while it dont give more stupid errors but still make the out of scoope ...
Have you tried copying that part of the code to a different project and compiling it there? Just to test if the compiler really has gone insane.
hmm i think i gonna reset the comp lol
here's the code:
PHP Code:string res;
int mod = 0;
int currentDivision;
int currentRes;
currentDivision = decimalNumber;
while (currentDivision > mod)
{
currentRes = currentDivision / 16;
mod = currentDivision % 16;
currentDivision = currentRes;
if (!(mod <= 9))
{
switch (mod)
{
case 10:
res += "A";
break;
case 11:
res += "B";
break;
case 12:
res += "C";
break;
case 13:
res += "D";
break;
case 14:
res += "E";
break;
case 15:
res += "F";
break;
}
}
else
{
res += mod.ToString();
}
}
MessageBox.Show(res);
return "";
tryed in another project and still the same damn bug omg how do i do this then?
omg it seems like i cant use variables inside a switch?
I think you need to initialize your res variable. There needs to be something in there before you concatentate to it.
I think the problem might be with the else statement. I removed the else statement and put a default in. Try this.
Code:string res;
int mod = 0;
int currentDivision;
int currentRes;
currentDivision = decimalNumber;
while (currentDivision > mod)
{
currentRes = currentDivision / 16;
mod = currentDivision % 16;
currentDivision = currentRes;
if (!(mod <= 9))
{
switch (mod)
{
case 10:
res += "A";
break;
case 11:
res += "B";
break;
case 12:
res += "C";
break;
case 13:
res += "D";
break;
case 14:
res += "E";
break;
case 15:
res += "F";
break;
default:
res += mod.ToString();
break;
}
}
}
MessageBox.Show(res);
return "";
Scott is right. You have to initialize a variable before using one of its members. Your shortcut operator accesses a member before initialization. Initialize the variable to zero and you should be able to keep your else construct.
yea it was initialization that the problem ocurred...welll..but i dunno why that damn bug givin error in every single operator lol
Well, because every single operator does an operation on an uninitialized variable.
Just initialize your res variable when you declare it:
string res = "";