help!! in c++...i can't do a ejercice

Discussion in 'C++' started by mathcen, Dec 20, 2007.

  1. mathcen

    mathcen Guest

    hi everyone...i need you help please..i need to do a ejercice, i'm a
    student..
    i have this table
    #define COLS 4

    #define ROWS 5

    int Sum[COLS] = { 0 };


    int Array[ROWS][COLS] =

    {

    { 192, 48, 206, 45 },

    { 180, 20, 320, 16 },

    { 221, 90, 140, 20 },

    { 432, 50, 821, 14 },

    { 820, 61, 946, 18 },

    };

    and § print the data in similar screen to the previous table,
    remembers to use repetitive. § printf at the end of each column the
    total of votes of each candidate. § printf in outstanding form the
    voted candidate more. § Add one more a row to the table than
    indicates, if the candidate obtained 50% of the votes, winner, the
    others second round.

    thanks you very much for you help!!!!!!!
     
    mathcen, Dec 20, 2007
    #1
    1. Advertising

  2. On Dec 20, 10:11 am, mathcen <> wrote:
    > hi everyone...i need you help please..i need to do a ejercice, i'm a
    > student..
    > i have this table
    > #define COLS 4
    >
    > #define ROWS 5
    >
    > int Sum[COLS] = { 0 };
    >
    > int Array[ROWS][COLS] =
    >
    > {
    >
    > { 192, 48, 206, 45 },
    >
    > { 180, 20, 320, 16 },
    >
    > { 221, 90, 140, 20 },
    >
    > { 432, 50, 821, 14 },
    >
    > { 820, 61, 946, 18 },
    >
    > };
    >
    > and § print the data in similar screen to the previous table,
    > remembers to use repetitive. § printf at the end of each column the
    > total of votes of each candidate. § printf in outstanding form the
    > voted candidate more. § Add one more a row to the table than
    > indicates, if the candidate obtained 50% of the votes, winner, the
    > others second round.
    >
    > thanks you very much for you help!!!!!!!


    1. No-one is going to do your homework for you: see
    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.2

    2. But, have a go, post what you've done, and people *will* help you.

    3. Don't rely on raw Babelfish output to translate your assignment
    - parts of your last paragraph don't make sense in English.
     
    tragomaskhalos, Dec 20, 2007
    #2
    1. Advertising

  3. mathcen

    mathcen Guest

    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <dos.h>


    #define COLS 4

    #define ROWS 5

    int Sum[COLS] = { 0 };


    int Array[ROWS][COLS] =

    {

    { 192, 48, 206, 45 },

    { 180, 20, 320, 16 },

    { 221, 90, 140, 20 },

    { 432, 50, 821, 14 },

    { 820, 61, 946, 18 },

    };



    int main(int argc, char **argv)

    {


    clrscr();

    for (int row=0; row<ROWS; ++row)

    {

    printf(" %d\t", row+1);

    for (int col=0; col<COLS; ++col)
    {
    printf("%d\t", Array[row][col]);

    Sum[col] += Array[row][col];



    }

    printf("\n");
    }

    for (int col=0; col<COLS; ++col)

    printf(" %d\t", Sum[col]);

    if( (col[3]>>col[1])&&(col[3]>>col[2])&&(col[3]>>col[4]) )

    {

    printf(" el candidato c obtuvo mas votos..");
    }




    getch();
    }

    Sorry that you misundertood me, Iwas not looking for you to do my
    homework just looking for some guidence. Please se attched my current
    work and if you believe are you able to provide me some advice, help I
    would really appreciate.
     
    mathcen, Dec 20, 2007
    #3
  4. On Dec 20, 12:54 pm, mathcen <> wrote:
    > #include <stdio.h>
    > #include <conio.h>
    > #include <stdlib.h>
    > #include <dos.h>
    >
    > #define COLS 4
    >
    > #define ROWS 5
    >
    > int Sum[COLS] = { 0 };
    >
    > int Array[ROWS][COLS] =
    >
    > {
    >
    > { 192, 48, 206, 45 },
    >
    > { 180, 20, 320, 16 },
    >
    > { 221, 90, 140, 20 },
    >
    > { 432, 50, 821, 14 },
    >
    > { 820, 61, 946, 18 },
    >
    > };
    >
    > int main(int argc, char **argv)
    >
    > {
    >
    > clrscr();
    >
    > for (int row=0; row<ROWS; ++row)
    >
    > {
    >
    > printf(" %d\t", row+1);
    >
    > for (int col=0; col<COLS; ++col)
    > {
    > printf("%d\t", Array[row][col]);
    >
    > Sum[col] += Array[row][col];
    >
    > }
    >
    > printf("\n");
    > }
    >
    > for (int col=0; col<COLS; ++col)
    >
    > printf(" %d\t", Sum[col]);
    >
    > if( (col[3]>>col[1])&&(col[3]>>col[2])&&(col[3]>>col[4]) )
    >
    > {
    >
    > printf(" el candidato c obtuvo mas votos..");
    >
    > }
    >
    > getch();
    >
    > }
    >
    > Sorry that you misundertood me, Iwas not looking for you to do my
    > homework just looking for some guidence. Please se attched my current
    > work and if you believe are you able to provide me some advice, help I
    > would really appreciate.


    Some general points:
    = You've posted code: good. However, you haven't said what your
    problems are with it, what the output is, where you're stuck -
    help others to help you by giving this info.

    = Your use of ROWS and COLS makes it very difficult to understand
    what the code is supposed to be doing - we only know it's about
    "candidates" because of the printf statement, and "votes" are
    nowhere to be seen.

    = "if( (col[3]>>col[1])&&(col[3]>>col[2])&&(col[3]>>col[4]) )"
    Are you trying to find a maximum value here ?
    This line will compile but does not do what I presume you think it
    does: >> is a right shift - greater-than-or-equal to is >=.
    The simple way to find a maximum value is as follows:
    ; initialize "max" to the smallest possible value (eg 0 or -Infinity)
    ; in a loop, for each value, if value > max then set max = value
     
    tragomaskhalos, Dec 20, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shapper
    Replies:
    1
    Views:
    392
    Scott Allen
    May 6, 2005
  2. craig dicker
    Replies:
    1
    Views:
    400
    Peter Rilling
    Jul 10, 2005
  3. Newsguy
    Replies:
    4
    Views:
    420
    Gary Dale
    Oct 22, 2005
  4. Replies:
    1
    Views:
    419
    Knute Johnson
    Sep 26, 2006
  5. Casey Hawthorne
    Replies:
    1
    Views:
    756
    Arne Vajhøj
    Mar 18, 2009
Loading...

Share This Page