Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Numbers game

C# Numbers game

Scheduled Pinned Locked Moved C#
csharpdelphicomgame-devhelp
27 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Pavlex4

    I have converted game from pascal to C# but when I start program and type in target value and values for finding that value program gives me error:[^] Pascal source: [Pascal] Moj Broj - Pastebin.com[^] C# Source: [C#] Moj Broj C# - Pastebin.com[^]

    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #2

    You've asked enough questions here to know how to ask a question: and linking to code on a different site isn't good. And just dumping two sets of code on us and saying "it don't work" isn't going to get you very far either. We've already told you that just blindly converting between Pascal and C# is a good idea. What have you done to sort this out? What have you found out about this problem by using the debugger?

    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    P 1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      You've asked enough questions here to know how to ask a question: and linking to code on a different site isn't good. And just dumping two sets of code on us and saying "it don't work" isn't going to get you very far either. We've already told you that just blindly converting between Pascal and C# is a good idea. What have you done to sort this out? What have you found out about this problem by using the debugger?

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      P Offline
      P Offline
      Pavlex4
      wrote on last edited by
      #3

      I change from bool[] uzet=new bool[6]; to bool[] uzet=new bool[7]; but I get this error: void oznaci_po_redu(int s) { l = 0; while (s > 0) { l++; if (!uzet[l]) s--; -----Index was outside the bounds of the array-------- } uzet[l] = true; }

      OriginalGriffO 1 Reply Last reply
      0
      • P Pavlex4

        I change from bool[] uzet=new bool[6]; to bool[] uzet=new bool[7]; but I get this error: void oznaci_po_redu(int s) { l = 0; while (s > 0) { l++; if (!uzet[l]) s--; -----Index was outside the bounds of the array-------- } uzet[l] = true; }

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #4

        Well, clearly you need to find out what value s has before you enter the loop, and why it might be larger than the number of elements. We can't do that for you: you need the debugger to find out!

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        P L 2 Replies Last reply
        0
        • OriginalGriffO OriginalGriff

          Well, clearly you need to find out what value s has before you enter the loop, and why it might be larger than the number of elements. We can't do that for you: you need the debugger to find out!

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

          P Offline
          P Offline
          Pavlex4
          wrote on last edited by
          #5

          Value of s before entering loop was 1

          OriginalGriffO 1 Reply Last reply
          0
          • P Pavlex4

            Value of s before entering loop was 1

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #6

            Then look at the code using the debugger and see exactly what is happening each time it goes round the loop. It's pretty obvious if you just pay attention to what you have written ... and the debugger would show that that immediately...

            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Well, clearly you need to find out what value s has before you enter the loop, and why it might be larger than the number of elements. We can't do that for you: you need the debugger to find out!

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #7

              The index variable is I.

              OriginalGriffO 1 Reply Last reply
              0
              • L Lost User

                The index variable is I.

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #8

                No, it's l

                void oznaci_po_redu(int s)
                {
                l = 0;
                while (s > 0)
                {
                l++;
                if (!uzet[l]) s--; -----Index was outside the bounds of the array--------
                }
                uzet[l] = true;
                }

                But it gets increased while s is non zero, and when does s get reduced?

                Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                L 1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  No, it's l

                  void oznaci_po_redu(int s)
                  {
                  l = 0;
                  while (s > 0)
                  {
                  l++;
                  if (!uzet[l]) s--; -----Index was outside the bounds of the array--------
                  }
                  uzet[l] = true;
                  }

                  But it gets increased while s is non zero, and when does s get reduced?

                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #9

                  My bad. And looking more closely at the code, I now see what you were alluding to.

                  OriginalGriffO 1 Reply Last reply
                  0
                  • L Lost User

                    My bad. And looking more closely at the code, I now see what you were alluding to.

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #10

                    :-D A quick visit with Mr Debug would have shown the OP as well! :laugh:

                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    P L 2 Replies Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      :-D A quick visit with Mr Debug would have shown the OP as well! :laugh:

                      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                      P Offline
                      P Offline
                      Pavlex4
                      wrote on last edited by
                      #11

                      I changed this loop for (prog.u = 1; prog.u < 6; prog.u++) to for (prog.u = 0; prog.u < 5; prog.u++) now I have this error: imageshack.com/a/img923/8677/WIBoHG.png

                      L OriginalGriffO 2 Replies Last reply
                      0
                      • P Pavlex4

                        I changed this loop for (prog.u = 1; prog.u < 6; prog.u++) to for (prog.u = 0; prog.u < 5; prog.u++) now I have this error: imageshack.com/a/img923/8677/WIBoHG.png

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #12

                        And the message is telling you exactly what is wrong.

                        1 Reply Last reply
                        0
                        • P Pavlex4

                          I changed this loop for (prog.u = 1; prog.u < 6; prog.u++) to for (prog.u = 0; prog.u < 5; prog.u++) now I have this error: imageshack.com/a/img923/8677/WIBoHG.png

                          OriginalGriffO Offline
                          OriginalGriffO Offline
                          OriginalGriff
                          wrote on last edited by
                          #13

                          And what error is that? It's less work for you to copy and paste the actual text, than to post a screen shot on a dodgy image site that I'm not planning on visiting...

                          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                          P 1 Reply Last reply
                          0
                          • OriginalGriffO OriginalGriff

                            And what error is that? It's less work for you to copy and paste the actual text, than to post a screen shot on a dodgy image site that I'm not planning on visiting...

                            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                            P Offline
                            P Offline
                            Pavlex4
                            wrote on last edited by
                            #14

                            Error is: Attempted to divide by zero.

                            OriginalGriffO 1 Reply Last reply
                            0
                            • P Pavlex4

                              Error is: Attempted to divide by zero.

                              OriginalGriffO Offline
                              OriginalGriffO Offline
                              OriginalGriff
                              wrote on last edited by
                              #15

                              Well, the error message pretty much explains itself. Mathematics does not allow you to divide by zero, so you should probably make sure your application doesn't try to do that, wouldn't you say? The fun bit is finding out why your application is trying at all. And - again - that's where you and Mr Debugger get to be good friends, because he's the one that tells you how the divisor came to be zero: which is pretty much essential to preventing it in future. Seriously, get used to the debugger - it's a powerful, flexible tool that most developers spend a considerable amount of time with. It's a lot more fun - and a lot quicker - to find the information than it is to ask here. Especially as most of the time we have to say "use the debugger to get information" anyway! :laugh:

                              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                              P 1 Reply Last reply
                              0
                              • OriginalGriffO OriginalGriff

                                Well, the error message pretty much explains itself. Mathematics does not allow you to divide by zero, so you should probably make sure your application doesn't try to do that, wouldn't you say? The fun bit is finding out why your application is trying at all. And - again - that's where you and Mr Debugger get to be good friends, because he's the one that tells you how the divisor came to be zero: which is pretty much essential to preventing it in future. Seriously, get used to the debugger - it's a powerful, flexible tool that most developers spend a considerable amount of time with. It's a lot more fun - and a lot quicker - to find the information than it is to ask here. Especially as most of the time we have to say "use the debugger to get information" anyway! :laugh:

                                Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                                P Offline
                                P Offline
                                Pavlex4
                                wrote on last edited by
                                #16

                                When I changed all loops to start from 0 to n-1,those that start with other number than 0 I set to start from value reduced by 1 to n-1 I still get error: Index was outside the bounds of the array

                                OriginalGriffO 1 Reply Last reply
                                0
                                • P Pavlex4

                                  When I changed all loops to start from 0 to n-1,those that start with other number than 0 I set to start from value reduced by 1 to n-1 I still get error: Index was outside the bounds of the array

                                  OriginalGriffO Offline
                                  OriginalGriffO Offline
                                  OriginalGriff
                                  wrote on last edited by
                                  #17

                                  And? What did the debugger show you?

                                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                  P 1 Reply Last reply
                                  0
                                  • OriginalGriffO OriginalGriff

                                    And? What did the debugger show you?

                                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                                    P Offline
                                    P Offline
                                    Pavlex4
                                    wrote on last edited by
                                    #18

                                    I fixed that error but when I start program and input target value and values I get wrong expression. When I type 100 for target number and numbers 5,8,9,4,20,50 for making expression I get: 5150-(' + w + ')+5355+5150 Instead of: (6-1)*4*5

                                    OriginalGriffO D 2 Replies Last reply
                                    0
                                    • P Pavlex4

                                      I fixed that error but when I start program and input target value and values I get wrong expression. When I type 100 for target number and numbers 5,8,9,4,20,50 for making expression I get: 5150-(' + w + ')+5355+5150 Instead of: (6-1)*4*5

                                      OriginalGriffO Offline
                                      OriginalGriffO Offline
                                      OriginalGriff
                                      wrote on last edited by
                                      #19

                                      At the risk of repeating myself:

                                      Quote:

                                      And? What did the debugger show you?

                                      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                                      1 Reply Last reply
                                      0
                                      • OriginalGriffO OriginalGriff

                                        :-D A quick visit with Mr Debug would have shown the OP as well! :laugh:

                                        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #20

                                        OriginalGriff wrote:

                                        visit with Mr Debug would have shown the OP

                                        Why bother when you can be a help vampire?

                                        Speed of sound - 1100 ft/sec Speed of light - 186,000 mi/sec Speed of stupid - instantaneous.

                                        OriginalGriffO 1 Reply Last reply
                                        0
                                        • P Pavlex4

                                          I fixed that error but when I start program and input target value and values I get wrong expression. When I type 100 for target number and numbers 5,8,9,4,20,50 for making expression I get: 5150-(' + w + ')+5355+5150 Instead of: (6-1)*4*5

                                          D Offline
                                          D Offline
                                          Dave Kreskowiak
                                          wrote on last edited by
                                          #21

                                          OK. Sit down and listen up. Your'e trying to get everyone here to debug your code for you. That's not going to happen. The debugger is there to debug YOU, to give you a tool to understands how your code works, what it's really doing, to increase your understanding. USE IT. The problem with the code you have is that you didn't write it and have no idea how it's supposed to work. This is where the debugger is an indispensable tool, to better your understanding of how the code works. We can't do that for you.

                                          A guide to posting questions on CodeProject

                                          Click this: Asking questions is a skill. Seriously, do it.
                                          Dave Kreskowiak

                                          OriginalGriffO 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups