Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Multiply a variable by 10  (Read 6941 times)

0 Members and 1 Guest are viewing this topic.

devcom



    Apprentice

    Thanked: 37
    Re: Multiple a variable by 10
    « Reply #15 on: November 23, 2008, 02:22:28 PM »
    @up
    is the %class% set before becouse it looks like you are seting %alliance% and trying to match %class%
    Download: Choice.exe

    gamerx365

      Topic Starter


      Adviser
    • Radda Radda!
    • Thanked: 1
      • Yes
      • Yes
    • Experience: Experienced
    • OS: Windows 10
    Re: Multiply a variable by 10
    « Reply #16 on: November 23, 2008, 02:49:39 PM »
    yes this code would come right after the class is set.

    Jacob



      Hopeful

      Thanked: 1
      • Experience: Expert
      • OS: Windows XP
      Re: Multiply a variable by 10
      « Reply #17 on: November 24, 2008, 09:24:50 AM »
      Seems like you didn't pick up on my post:
      Code: [Select]
      set /a lifetemp=%life%*10
      set life=%lifetemp%

      gamerx365

        Topic Starter


        Adviser
      • Radda Radda!
      • Thanked: 1
        • Yes
        • Yes
      • Experience: Experienced
      • OS: Windows 10
      Re: Multiply a variable by 10
      « Reply #18 on: November 24, 2008, 02:27:27 PM »
      oh yeah.i tired it. nothing. maybe my computers just retarded. sometimes batch files do get a little messed up on it but its usually fine after I restart it. it didn't help this time.

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Multiply a variable by 10
      « Reply #19 on: November 24, 2008, 02:36:07 PM »
      It is a bug somewhere else.

      Code: [Select]
      rem assignment code
      set /a life=40
      set /a life=%life%*10
      echo %life%

      gave me 400.

      there is likely a bug elsewhere in your code- causing your variables to have unexpected values when you arrive at the arithmetic.

      I have a proposed change:

      Code: [Select]
      :allianceselect
      CLS
      ECHO Choose your alliance:
      ECHO.
      ECHO 1) Good
      ECHO 2) Evil
      ECHO.
      set /p alliance=
      ECHO alliance>%alliance%.alliance
      ECHO alliance>alliance
      ECHO class is:
      echo %class%
      pause
      IF '%class%'=='1' SET alliancename=Good
      IF '%class%'=='2' SET alliancename=Evil
      IF '%class%'=='1' SET /A life=10 * %life%
      IF '%class%'=='2' SET /A armor=10 * %armor%

      DEL *.life
      DEL *.armor
      ECHO life>%life%.life
      ECHO armor>%armor%.armor
      GOTO lobby


      this will ascertain wether your %class% variable even has a value when you try to use it.
      I was trying to dereference Null Pointers before it was cool.

      gamerx365

        Topic Starter


        Adviser
      • Radda Radda!
      • Thanked: 1
        • Yes
        • Yes
      • Experience: Experienced
      • OS: Windows 10
      Re: Multiply a variable by 10
      « Reply #20 on: November 24, 2008, 02:53:20 PM »
      i've got it. thanks for the code, but it didnt much help. well, actually it did help me realize my error. im surprised it took even me this long to figure out this dumb mistake lol.

      new code:
      Code: [Select]
      set /p alliance=
      ECHO alliance>%alliance%.alliance
      ECHO alliance>alliance
      IF '%alliance%'=='1' SET alliancename=Good
      IF '%alliance%'=='2' SET alliancename=Evil
      IF '%alliance%'=='1' SET /A life=10 * %life%
      IF '%alliance%'=='2' SET /A armor=10 * %armor%

      old code:
      Code: [Select]
      set /p alliance=
      ECHO alliance>%alliance%.alliance
      ECHO alliance>alliance
      IF '%class%'=='1' SET alliancename=Good
      IF '%class%'=='2' SET alliancename=Evil
      IF '%class%'=='1' SET /A life=10 * %life%
      IF '%class%'=='2' SET /A armor=10 * %armor%

      just in case anyone's curious.

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Multiply a variable by 10
      « Reply #21 on: November 24, 2008, 02:54:58 PM »
      lol. and after all that work to multiply by 2... I mean, 10.
      I was trying to dereference Null Pointers before it was cool.

      gamerx365

        Topic Starter


        Adviser
      • Radda Radda!
      • Thanked: 1
        • Yes
        • Yes
      • Experience: Experienced
      • OS: Windows 10
      Re: Multiply a variable by 10
      « Reply #22 on: November 24, 2008, 02:59:46 PM »
      lol yeah. i copy and pasted that code in there 5 times and it didn't work once!

      lol.

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Multiply a variable by 10
      « Reply #23 on: November 24, 2008, 03:17:06 PM »
      erm... multiplying a number by 2 five times isn't the same as multiplying by 10 anyways.
      I was trying to dereference Null Pointers before it was cool.

      gamerx365

        Topic Starter


        Adviser
      • Radda Radda!
      • Thanked: 1
        • Yes
        • Yes
      • Experience: Experienced
      • OS: Windows 10
      Re: Multiply a variable by 10
      « Reply #24 on: November 24, 2008, 03:22:56 PM »
      I know. but neither statement made sense. I thought I'd poke a little more fun at that.

      devcom



        Apprentice

        Thanked: 37
        Re: Multiply a variable by 10
        « Reply #25 on: November 25, 2008, 02:30:44 PM »
        i've got it. thanks for the code, but it didnt much help. well, actually it did help me realize my error. im surprised it took even me this long to figure out this dumb mistake lol.

        new code:
        Code: [Select]
        set /p alliance=
        ECHO alliance>%alliance%.alliance
        ECHO alliance>alliance
        IF '%alliance%'=='1' SET alliancename=Good
        IF '%alliance%'=='2' SET alliancename=Evil
        IF '%alliance%'=='1' SET /A life=10 * %life%
        IF '%alliance%'=='2' SET /A armor=10 * %armor%

        old code:
        Code: [Select]
        set /p alliance=
        ECHO alliance>%alliance%.alliance
        ECHO alliance>alliance
        IF '%class%'=='1' SET alliancename=Good
        IF '%class%'=='2' SET alliancename=Evil
        IF '%class%'=='1' SET /A life=10 * %life%
        IF '%class%'=='2' SET /A armor=10 * %armor%

        just in case anyone's curious.

        that was what i mean in last post  ::)
        Quote
        is the %class% set before becouse it looks like you are seting %alliance% and trying to match %class%
        Download: Choice.exe

        gamerx365

          Topic Starter


          Adviser
        • Radda Radda!
        • Thanked: 1
          • Yes
          • Yes
        • Experience: Experienced
        • OS: Windows 10
        Re: Multiply a variable by 10
        « Reply #26 on: November 25, 2008, 02:48:28 PM »
        yes class was set before. the problem was it was being set as 3... lol. thats why i was so confused.