Sunday, July 12, 2009

Help with c++ program please?

ok I have a program that reads in values from a file which contains a bunch of numbers, it tallies these numbers as votes in 6 different races and prints out the number of votes for each candidate as well as the winner and the percentage of votes, i need to rewrite the program using arrays which i dont know how to do, heres the program:


#include%26lt;iostream%26gt;


#include%26lt;fstream%26gt;


using namespace std;


void


tally(int%26amp;,int%26amp;,int%26amp;,int%26amp;,int%26amp;...


void print(int, int, int, int);





int main() {


int p1=0,p2=0,vp1=0,vp2=0,s1=0,s2=...


int vote;








ifstream voter;


voter.open("ballot.txt");














while(!voter.eof()){

Help with c++ program please?
Well its been a while since I used C++ but the way you can do it logically is to just add each vote to the array index. Just take the first number and add it in to the 0 index. Then the second number into the 1'st index ect.


add it by:





int x = 0;





while(x%26lt;array.length())


{


array[x] = numberOfVotes;


x++;


}





with the print.








int y = 0;





while(y%26lt;array.length())


{


cout%26lt;%26lt;array[y];


}


No comments:

Post a Comment