Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > help!! in c++...i can't do a ejercice

Reply
Thread Tools

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

 
 
mathcen
Guest
Posts: n/a
 
      12-20-2007
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!!!!!!!
 
Reply With Quote
 
 
 
 
tragomaskhalos
Guest
Posts: n/a
 
      12-20-2007
On Dec 20, 10:11 am, mathcen <(E-Mail Removed)> 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-lit...t.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.


 
Reply With Quote
 
 
 
 
mathcen
Guest
Posts: n/a
 
      12-20-2007
#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.


 
Reply With Quote
 
tragomaskhalos
Guest
Posts: n/a
 
      12-20-2007
On Dec 20, 12:54 pm, mathcen <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments