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

M

mathcen

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!!!!!!!
 
T

tragomaskhalos

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.
 
M

mathcen

#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.
 
T

tragomaskhalos

#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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top