|
-
Nov 8th, 2002, 10:06 AM
#1
Thread Starter
yay gay
variable scoope
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!
-
Nov 8th, 2002, 10:09 AM
#2
Thread Starter
yay gay
omg my IDE gone insane..now it points error to any operator just like += , % etc..omg LOL
-
Nov 8th, 2002, 10:10 AM
#3
Thread Starter
yay gay
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 ...
-
Nov 8th, 2002, 10:13 AM
#4
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 8th, 2002, 11:57 AM
#5
Thread Starter
yay gay
hmm i think i gonna reset the comp lol
-
Nov 8th, 2002, 12:05 PM
#6
Thread Starter
yay gay
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 "";
-
Nov 8th, 2002, 12:16 PM
#7
Thread Starter
yay gay
tryed in another project and still the same damn bug omg how do i do this then?
-
Nov 8th, 2002, 12:19 PM
#8
Thread Starter
yay gay
omg it seems like i cant use variables inside a switch?
-
Nov 8th, 2002, 01:21 PM
#9
Hyperactive Member
I think you need to initialize your res variable. There needs to be something in there before you concatentate to it.
-scott
he he he
-
Nov 8th, 2002, 01:32 PM
#10
Frenzied Member
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 "";
Dont gain the world and lose your soul
-
Nov 8th, 2002, 02:08 PM
#11
PowerPoster
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.
-
Nov 8th, 2002, 02:54 PM
#12
Thread Starter
yay gay
yea it was initialization that the problem ocurred...welll..but i dunno why that damn bug givin error in every single operator lol
-
Nov 8th, 2002, 08:05 PM
#13
Well, because every single operator does an operation on an uninitialized variable.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 9th, 2002, 05:58 PM
#14
Just initialize your res variable when you declare it:
string res = "";
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|