Results 1 to 14 of 14

Thread: variable scoope

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    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!

  2. #2

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    omg my IDE gone insane..now it points error to any operator just like += , % etc..omg LOL

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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 ...

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  5. #5

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm i think i gonna reset the comp lol

  6. #6

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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 
    ""

  7. #7

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    tryed in another project and still the same damn bug omg how do i do this then?

  8. #8

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    omg it seems like i cant use variables inside a switch?

  9. #9
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327
    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

  10. #10
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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

  11. #11
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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.

  12. #12

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    yea it was initialization that the problem ocurred...welll..but i dunno why that damn bug givin error in every single operator lol

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  14. #14
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    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
  •  



Click Here to Expand Forum to Full Width