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. Hello folks

Hello folks

Scheduled Pinned Locked Moved C#
tutorial
28 Posts 9 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.
  • M MoeInsairat

    Please i need this answer asap.. if i want to do a function that accepts INTEGERS number... then i wanna the sum of these integers.. for example if i entered 123.. the answer should be 6. Thanks in advance Regards

    Estarta

    S Offline
    S Offline
    Stefan Troschuetz
    wrote on last edited by
    #3

    Almost certainly no one here will write the whole thing for you. Show us what you got so far, say concretely where you got stuck and we'll help you. By the way, the specification of your function is quite lousy. It is not really clear what the input is; integers, an array of integers or maybe a string with integers? From your example it seams to be the latter. If so, do you want to sum up the digits or how should the function know where to break up the string into integers?


    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

    www.troschuetz.de

    M 1 Reply Last reply
    0
    • C Colin Angus Mackay

      Sounds like homework. Why don't you make an attempt and then we'll help you with that?


      Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

      M Offline
      M Offline
      MoeInsairat
      wrote on last edited by
      #4

      Thanks for ur reply, And its not a homework, and i tried so many time i couldn't do it :~~ i just wanted to know thanks

      Estarta

      1 Reply Last reply
      0
      • S Stefan Troschuetz

        Almost certainly no one here will write the whole thing for you. Show us what you got so far, say concretely where you got stuck and we'll help you. By the way, the specification of your function is quite lousy. It is not really clear what the input is; integers, an array of integers or maybe a string with integers? From your example it seams to be the latter. If so, do you want to sum up the digits or how should the function know where to break up the string into integers?


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        M Offline
        M Offline
        MoeInsairat
        wrote on last edited by
        #5

        Well its only INTEGERS not array any intergers. and yesterday i had this work interview and they asked me this question and it bothers me :(

        Estarta

        M C 2 Replies Last reply
        0
        • M MoeInsairat

          Well its only INTEGERS not array any intergers. and yesterday i had this work interview and they asked me this question and it bothers me :(

          Estarta

          M Offline
          M Offline
          MoeInsairat
          wrote on last edited by
          #6

          i've tried, but i can't get it done! there is must be an array but how can i know how many digits are there without convert the input to string!

          Estarta

          1 Reply Last reply
          0
          • M MoeInsairat

            Please i need this answer asap.. if i want to do a function that accepts INTEGERS number... then i wanna the sum of these integers.. for example if i entered 123.. the answer should be 6. Thanks in advance Regards

            Estarta

            R Offline
            R Offline
            rah_sin
            wrote on last edited by
            #7

            try out public void sumOfInt(int num) { int tot =0; string nubstr = num.ToString(); for(int y=0;y < nubstr.Length; y++) { int sub = int.Parse(nubstr.Substring(y,1)); tot=tot+sub; } MessageBox.Show("Sum of Integers"+" "+tot.ToString()); }

            rahul

            M G 2 Replies Last reply
            0
            • R rah_sin

              try out public void sumOfInt(int num) { int tot =0; string nubstr = num.ToString(); for(int y=0;y < nubstr.Length; y++) { int sub = int.Parse(nubstr.Substring(y,1)); tot=tot+sub; } MessageBox.Show("Sum of Integers"+" "+tot.ToString()); }

              rahul

              M Offline
              M Offline
              MoeInsairat
              wrote on last edited by
              #8

              Thanks buddy :)

              Estarta

              1 Reply Last reply
              0
              • M MoeInsairat

                Well its only INTEGERS not array any intergers. and yesterday i had this work interview and they asked me this question and it bothers me :(

                Estarta

                C Offline
                C Offline
                Colin Angus Mackay
                wrote on last edited by
                #9

                Estarta wrote:

                and yesterday i had this work interview and they asked me this question and it bothers me

                :omg: I'd say that the job isn't the right one for you. This question is a variation (at least on the same level) as FizzBuzz For more information listen to this podcast[^] or read the transcript[^] Anyone with a software development job should be able to do that in a couple of minutes


                Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

                M 2 Replies Last reply
                0
                • C Colin Angus Mackay

                  Estarta wrote:

                  and yesterday i had this work interview and they asked me this question and it bothers me

                  :omg: I'd say that the job isn't the right one for you. This question is a variation (at least on the same level) as FizzBuzz For more information listen to this podcast[^] or read the transcript[^] Anyone with a software development job should be able to do that in a couple of minutes


                  Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

                  M Offline
                  M Offline
                  MoeInsairat
                  wrote on last edited by
                  #10

                  Well thanks :)

                  Estarta

                  1 Reply Last reply
                  0
                  • C Colin Angus Mackay

                    Estarta wrote:

                    and yesterday i had this work interview and they asked me this question and it bothers me

                    :omg: I'd say that the job isn't the right one for you. This question is a variation (at least on the same level) as FizzBuzz For more information listen to this podcast[^] or read the transcript[^] Anyone with a software development job should be able to do that in a couple of minutes


                    Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

                    M Offline
                    M Offline
                    MoeInsairat
                    wrote on last edited by
                    #11

                    btw wat makes u think that this JOB is not right.. u don't even know me ;p

                    Estarta

                    S D P 3 Replies Last reply
                    0
                    • M MoeInsairat

                      btw wat makes u think that this JOB is not right.. u don't even know me ;p

                      Estarta

                      S Offline
                      S Offline
                      Stefan Troschuetz
                      wrote on last edited by
                      #12

                      Estarta wrote:

                      btw wat makes u think that this JOB is not right.. u don't even know me

                      He knows that you're not able to programmatically solve this quite simple problem on your own. Since the interview question implies the job has something to do with programming, your obviously not the right/best choice for the job and the other way round.


                      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

                      www.troschuetz.de

                      1 Reply Last reply
                      0
                      • M MoeInsairat

                        btw wat makes u think that this JOB is not right.. u don't even know me ;p

                        Estarta

                        D Offline
                        D Offline
                        Dan Neely
                        wrote on last edited by
                        #13

                        Anyone who passed CS101 should be able to do this in 5 minutes with one hand tied behind their back. If you can't, you should give up your software aspirations and take up a new career as a burger flipper.

                        -- CleaKO The sad part about this instance is that none of the users ever said anything [about the problem]. Pete O`Hanlon Doesn't that just tell you everything you need to know about users?

                        1 Reply Last reply
                        0
                        • R rah_sin

                          try out public void sumOfInt(int num) { int tot =0; string nubstr = num.ToString(); for(int y=0;y < nubstr.Length; y++) { int sub = int.Parse(nubstr.Substring(y,1)); tot=tot+sub; } MessageBox.Show("Sum of Integers"+" "+tot.ToString()); }

                          rahul

                          G Offline
                          G Offline
                          Guffa
                          wrote on last edited by
                          #14

                          Alternatively without using strings at all:

                          public int CrossSum(int value) {
                          int sum = 0;
                          while (value > 0) {
                          sum += value % 10;
                          value /= 10;
                          }
                          return sum;
                          }

                          Frankly, Estarta, if you are applying for a job as a programmer, you should be able to write something simple as this yourself.

                          --- single minded; short sighted; long gone;

                          M 1 Reply Last reply
                          0
                          • M MoeInsairat

                            btw wat makes u think that this JOB is not right.. u don't even know me ;p

                            Estarta

                            P Offline
                            P Offline
                            Pete OHanlon
                            wrote on last edited by
                            #15

                            We may not know you, but we've certainly cleaned up enough messes left by people just like you. The question was basic stuff - it shouldn't have bothered you. Even if you didn't know the ins and outs of the language, you should have been able to come up with the algorithm for it without needing to think about it. You should also have been able to explain the problem properly, without using txtspk. Overall, I'll take one Colin over 100 of you any day.

                            Deja View - the feeling that you've seen this post before.

                            M 1 Reply Last reply
                            0
                            • P Pete OHanlon

                              We may not know you, but we've certainly cleaned up enough messes left by people just like you. The question was basic stuff - it shouldn't have bothered you. Even if you didn't know the ins and outs of the language, you should have been able to come up with the algorithm for it without needing to think about it. You should also have been able to explain the problem properly, without using txtspk. Overall, I'll take one Colin over 100 of you any day.

                              Deja View - the feeling that you've seen this post before.

                              M Offline
                              M Offline
                              MoeInsairat
                              wrote on last edited by
                              #16

                              Well thanks again for the reply. but you know you don't have to say such things if you can erase my account so do it!! but don't act like the YOU ARE THE BEST or i dont know wats the matter with u!!! i asked a question AND I DON'T KNOW THE ANSWER nth to be shamed of!!! and btw i`m a software engineer we didn't took PROGRAMMING LANGUAGES as u did !! we only took the software engineering syuff and rational rose!! You dont even deserve my reply!!! Good bye MR

                              Estarta

                              P C 2 Replies Last reply
                              0
                              • M MoeInsairat

                                Well thanks again for the reply. but you know you don't have to say such things if you can erase my account so do it!! but don't act like the YOU ARE THE BEST or i dont know wats the matter with u!!! i asked a question AND I DON'T KNOW THE ANSWER nth to be shamed of!!! and btw i`m a software engineer we didn't took PROGRAMMING LANGUAGES as u did !! we only took the software engineering syuff and rational rose!! You dont even deserve my reply!!! Good bye MR

                                Estarta

                                P Offline
                                P Offline
                                Pete OHanlon
                                wrote on last edited by
                                #17

                                By definition, a software engineer has to be able to break algorithms down. You couldn't. You're right, there's nothing to be ashamed of when you don't know the answer to a problem - unless that problem is basic. I would be interested to know how you think you are a software engineer if you didn't do any programming languages. Colin pointed out to you that you may not be pursuing the right career. I pointed out to you why I thought he'd done so because you couldn't seem to grasp this. Your answer has compounded the issue. As a professional developer, I have spent a large amount of time mentoring and helping newbie developers but I would advise anybody who couldn't get a grasp on such a basic problem to steer clear of a career in developing. More importantly, as I stated earlier, I have spent a large amount of time clearing up after people who shouldn't have been developers in the first place. If you want to prove me wrong, brush up on your algorithms, learn the basics and then move onto more advanced things.

                                Deja View - the feeling that you've seen this post before.

                                M 1 Reply Last reply
                                0
                                • P Pete OHanlon

                                  By definition, a software engineer has to be able to break algorithms down. You couldn't. You're right, there's nothing to be ashamed of when you don't know the answer to a problem - unless that problem is basic. I would be interested to know how you think you are a software engineer if you didn't do any programming languages. Colin pointed out to you that you may not be pursuing the right career. I pointed out to you why I thought he'd done so because you couldn't seem to grasp this. Your answer has compounded the issue. As a professional developer, I have spent a large amount of time mentoring and helping newbie developers but I would advise anybody who couldn't get a grasp on such a basic problem to steer clear of a career in developing. More importantly, as I stated earlier, I have spent a large amount of time clearing up after people who shouldn't have been developers in the first place. If you want to prove me wrong, brush up on your algorithms, learn the basics and then move onto more advanced things.

                                  Deja View - the feeling that you've seen this post before.

                                  M Offline
                                  M Offline
                                  MoeInsairat
                                  wrote on last edited by
                                  #18

                                  I Know the basics.. !! int x= int.Parse(Input.Text); int t =0; string i = x.ToString(); for(int y=0;yEstarta

                                  R S 2 Replies Last reply
                                  0
                                  • G Guffa

                                    Alternatively without using strings at all:

                                    public int CrossSum(int value) {
                                    int sum = 0;
                                    while (value > 0) {
                                    sum += value % 10;
                                    value /= 10;
                                    }
                                    return sum;
                                    }

                                    Frankly, Estarta, if you are applying for a job as a programmer, you should be able to write something simple as this yourself.

                                    --- single minded; short sighted; long gone;

                                    M Offline
                                    M Offline
                                    MoeInsairat
                                    wrote on last edited by
                                    #19

                                    Thats true. Thanks :)

                                    Estarta

                                    1 Reply Last reply
                                    0
                                    • M MoeInsairat

                                      I Know the basics.. !! int x= int.Parse(Input.Text); int t =0; string i = x.ToString(); for(int y=0;yEstarta

                                      R Offline
                                      R Offline
                                      Russell Jones
                                      wrote on last edited by
                                      #20

                                      that's quite a different question from the one you asked at the start :confused: Can i suggest not using the letter i to denote a string, even if it does contain the string representation of an integer. You should use Parse or TryParse on the input to make sure that the number can be represented as a number. Russell

                                      1 Reply Last reply
                                      0
                                      • M MoeInsairat

                                        I Know the basics.. !! int x= int.Parse(Input.Text); int t =0; string i = x.ToString(); for(int y=0;yEstarta

                                        S Offline
                                        S Offline
                                        Stefan Troschuetz
                                        wrote on last edited by
                                        #21

                                        Estarta wrote:

                                        This is wat i did!!and its working, but wat im asking is there is anyway i can do it without Parse the int to String?

                                        So why didn't you show us the code and asked exactly that question in the first place? Why did you told us "i've tried, but i can't get it done!"?


                                        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

                                        www.troschuetz.de

                                        M 1 Reply Last reply
                                        0
                                        • S Stefan Troschuetz

                                          Estarta wrote:

                                          This is wat i did!!and its working, but wat im asking is there is anyway i can do it without Parse the int to String?

                                          So why didn't you show us the code and asked exactly that question in the first place? Why did you told us "i've tried, but i can't get it done!"?


                                          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

                                          www.troschuetz.de

                                          M Offline
                                          M Offline
                                          MoeInsairat
                                          wrote on last edited by
                                          #22

                                          bcuz i've tried and maybe my question wasn't so clear.. i was trying to tell u guys i want the answer without parsing the input into integers.. anyway i got the answer thanks for ur time

                                          Estarta

                                          S 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