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 / C++ / MFC
  4. urgent help

urgent help

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
15 Posts 6 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.
  • G gentleguy

    still problem.....do u have other idea? thanks

    Li Zhiyuan 5/10/2006

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #4

    But did you read my reply? I need to know your requiremts, i.e. what should your code do? :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    [my articles]

    In testa che avete, signor di Ceprano?

    G 1 Reply Last reply
    0
    • CPalliniC CPallini

      But did you read my reply? I need to know your requiremts, i.e. what should your code do? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      [my articles]

      G Offline
      G Offline
      gentleguy
      wrote on last edited by
      #5

      double d[150]; double c[150][3],d[150] is a minimum value of c[150][3], so i want to accumulate how many numbers in column 1,2 and 3 respectively, and sum each column value. that is all..thanks a lot. for (int k = 0; k< 150; k++) { if (d[k] == c[k][0]) { sum1 = c[k][0]; sum1 = sum1 + 1; num1 = num1 + 1; } if (d[k] == c[k][1]) { sum2 = c[k][1]; sum2 = sum2 + 1; num2 = num2 + 1; } if (d[k] == c[k][2]) { sum3 = c[k][2]; sum3 = sum3 + 1; num3 = num3 + 1; }

      Li Zhiyuan 5/10/2006

      CPalliniC 1 Reply Last reply
      0
      • G gentleguy

        double d[150]; double c[150][3],d[150] is a minimum value of c[150][3], so i want to accumulate how many numbers in column 1,2 and 3 respectively, and sum each column value. that is all..thanks a lot. for (int k = 0; k< 150; k++) { if (d[k] == c[k][0]) { sum1 = c[k][0]; sum1 = sum1 + 1; num1 = num1 + 1; } if (d[k] == c[k][1]) { sum2 = c[k][1]; sum2 = sum2 + 1; num2 = num2 + 1; } if (d[k] == c[k][2]) { sum3 = c[k][2]; sum3 = sum3 + 1; num3 = num3 + 1; }

        Li Zhiyuan 5/10/2006

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #6

        something like the following?

        int n;
        int sum[3];
        int num[3];
        for (n=0; n<3; n++)
        {
        sum[n]=0;
        num[n]=0;
        }
        for (int k = 0; k< 150; k++)
        {
        for (n=0; n<3; n++)
        {
        if (d[k] == c[k][n])
        {
        sum[n] = sum[n] + d[k]; // or sum[n] += d[k]
        num[n] = num[n] + 1; // see the above remark
        }
        }
        }

        :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        [my articles]

        In testa che avete, signor di Ceprano?

        G 1 Reply Last reply
        0
        • G gentleguy

          dear all how to solve the following problem..thanks a lot.. for (int k = 0; k< 150; k++) { if (d[k] == c[k][0]) { sum1 = c[k][0]; sum1 = sum1 + 1; num1 = num1 + 1; } why sum1 can't accumulate..it always showed me 1 + the previous value...

          Li Zhiyuan 5/10/2006

          C Offline
          C Offline
          cp9876
          wrote on last edited by
          #7

          sum1 doesn't accumulate as you are assigning a fresh value to it:

          li zhiyuan wrote:

          sum1 = c[k][0];

          before you accumulate

          li zhiyuan wrote:

          sum1 = sum1 + 1;

          Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."

          1 Reply Last reply
          0
          • G gentleguy

            dear all how to solve the following problem..thanks a lot.. for (int k = 0; k< 150; k++) { if (d[k] == c[k][0]) { sum1 = c[k][0]; sum1 = sum1 + 1; num1 = num1 + 1; } why sum1 can't accumulate..it always showed me 1 + the previous value...

            Li Zhiyuan 5/10/2006

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #8

            li zhiyuan wrote:

            it always showed me 1 + the previous value...

            Because that's exactly what you've coded it to do. Computers do what they're told, no more, no less, which may not always be what you want.

            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            CPalliniC 1 Reply Last reply
            0
            • D David Crow

              li zhiyuan wrote:

              it always showed me 1 + the previous value...

              Because that's exactly what you've coded it to do. Computers do what they're told, no more, no less, which may not always be what you want.

              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #9

              DavidCrow wrote:

              Computers do what they're told, no more, no less

              You are a dreamer, my friend. :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              [my articles]

              In testa che avete, signor di Ceprano?

              D 1 Reply Last reply
              0
              • CPalliniC CPallini

                DavidCrow wrote:

                Computers do what they're told, no more, no less

                You are a dreamer, my friend. :-D

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                [my articles]

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #10

                CPallini wrote:

                You are a dreamer, my friend.

                How so?

                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                CPalliniC 1 Reply Last reply
                0
                • D David Crow

                  CPallini wrote:

                  You are a dreamer, my friend.

                  How so?

                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #11

                  Computers do anything but what you've told to do. ;P

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  [my articles]

                  In testa che avete, signor di Ceprano?

                  T M 2 Replies Last reply
                  0
                  • CPalliniC CPallini

                    Computers do anything but what you've told to do. ;P

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    [my articles]

                    T Offline
                    T Offline
                    tina newcoder
                    wrote on last edited by
                    #12

                    CPallini wrote:

                    Computers do anything but what you've told to do.

                    yeah .... i agree.... ! :)

                    1 Reply Last reply
                    0
                    • CPalliniC CPallini

                      Computers do anything but what you've told to do. ;P

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      [my articles]

                      M Offline
                      M Offline
                      Member 754960
                      wrote on last edited by
                      #13

                      Hard of hearing; practically deaf in some cases!

                      1 Reply Last reply
                      0
                      • CPalliniC CPallini

                        something like the following?

                        int n;
                        int sum[3];
                        int num[3];
                        for (n=0; n<3; n++)
                        {
                        sum[n]=0;
                        num[n]=0;
                        }
                        for (int k = 0; k< 150; k++)
                        {
                        for (n=0; n<3; n++)
                        {
                        if (d[k] == c[k][n])
                        {
                        sum[n] = sum[n] + d[k]; // or sum[n] += d[k]
                        num[n] = num[n] + 1; // see the above remark
                        }
                        }
                        }

                        :)

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        [my articles]

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

                        thanks, i tried your suggestion already, but still problem...num[n] is no problem, sum[n] still has problem, when i used sum[n] += d[k], the result is sum[0] = sum[1] = sum[2] = 0; if i used sum[n] = sum[n] + 1; the result is same with num[n], what happened? thanks

                        Li Zhiyuan 5/10/2006

                        G 1 Reply Last reply
                        0
                        • G gentleguy

                          thanks, i tried your suggestion already, but still problem...num[n] is no problem, sum[n] still has problem, when i used sum[n] += d[k], the result is sum[0] = sum[1] = sum[2] = 0; if i used sum[n] = sum[n] + 1; the result is same with num[n], what happened? thanks

                          Li Zhiyuan 5/10/2006

                          G Offline
                          G Offline
                          gentleguy
                          wrote on last edited by
                          #15

                          i already solved this problem, finally i found, i need to change array type from int to double, because array d is double..firstly, i misinitialed int...thanks

                          Li Zhiyuan 5/10/2006

                          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