Program Help! (C++)
ok hey guys i need some help with a program heres the code so far:
#include <iostream.h> #include "Rando.h" #include "apvector.h" long MAX; void print (apvector<long>&d); void fill (apvector<long>&d); void fill(apvector<long>&d) { RandGen rnd; int num=0; for (long i=0; i<MAX; i++) { d[i]+rnd.Randint(50000,100000); } }
void print (apvector<long>&d) { cout<<"Province"<<endl; cout<<"Poll #""\t\t\t" "Candidate #1: ""\t\t\t" "Candidate #2:"<<endl; long div=MAX/2; for (long i=0; i<div; i++) { cout.width(6); cout<<i+1; cout<<"\t\t\t"; cout.width(13); cout<<d[i]; cout<<"\t\t\t"; cout.width(13); cout<<d[i+div]<<endl; } } int main() { cout<<"enter number of polls"<<endl; cin>>MAX; MAX=MAX*2; apvector<long>dat(MAX); fill(dat); print(dat); system("pause"); return 0; }
and heres the output… enter number of polls 10 Province Poll # Candidate #1: Candidate #2: 1 56659 57539 2 75900 99485 3 95157 63162 4 79465 56883 5 56231 86563 6 94063 94658 7 79570 64982 8 90866 87145 9 84064 95350 10 56588 99375 Press any key to continue …
im wondering how i would get the total of all the polls in each coloum?
In the 'for' loop use 2 variables to store the results from each candidate
Example [UNTESTED]
**
long candidate1Total = 0;
long candidate2Total = 0;
**
for (long i=0; i<div; i++) {
cout.width(6);
cout<<i+1;
cout<<"\t\t\t";
cout.width(13);
cout<<d[i];
**candidate1Total += d[i];**
cout<<"\t\t\t";
cout.width(13);
cout<<d[i+div]<<endl;
**candidate2Total += d[i+div];**
}
Regards CyberLemming
This thread has been answered in the EnigmaGroup forums as far as I can see.