a code problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • husseinballard
    New Member
    • Mar 2010
    • 1

    a code problem

    this is a practice question that has me baffled
    I am providing my answer, but to tell you the truth I do not see enought info to
    answer the question. the question is : fill in the blank linebelow

    sum=0;
    for(k=0; k<50; k++)
    for (j=0; j<7; j++)
    sum= sum +______________ __
    my answer is sum =sum+ K ++ J ++

    but I have been told it was wrong, what is the solution?
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    You need a semicolon at the end of the line. I can't say much more than that without knowing what this code snippet is trying to accomplish.

    The double-plus (++) are almost certainly wrong; although I suppose it might be possible to invent a problem statement that required them.

    How does this relate to your almost identical other post? You shouldn't double-post.

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      You're already incrementing k and j in the for loop, why do it again?
      Plus variables are case sensitive, so you need to use j and k, not J and K.

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        What is sum supposed to be the sum of? Is it supposed to be the sum of itself and J and K?

        And why are you double posting?

        Comment

        • crztrane
          New Member
          • Mar 2010
          • 1

          #5
          My guess would be that sum is meant to be a counter for the number of times gone though the loop so could you try use 1?

          Comment

          • holyzuou
            New Member
            • Jan 2010
            • 13

            #6
            sum+ K ++ J ++:
            J++ is j=j+1;
            k++ is k=k+1
            So sum+k++J++ is sum+(k+1)(j+1) then what is the answer

            Comment

            • whodgson
              Contributor
              • Jan 2007
              • 542

              #7
              I believe jkmyoung has solved the problem.

              Comment

              • RedSon
                Recognized Expert Expert
                • Jan 2007
                • 4980

                #8
                why do you think that?

                Comment

                • holyzuou
                  New Member
                  • Jan 2010
                  • 13

                  #9
                  compiler can not identify k++J++

                  Comment

                  • whodgson
                    Contributor
                    • Jan 2007
                    • 542

                    #10
                    @RedSon
                    By saying that, I was attempting to encourage someone into providing the correct answer with its logic

                    Comment

                    Working...