Sunday, July 12, 2009

Someone help me with this 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()){

Someone help me with this c++ program please?
Think of an array as a row in an excel worksheet. Each cell is an array position. Each position has the same datatype. So, if you have 12 candidates, you could keep track of their votes in an array as follows:





int candidates[12];





Arrays always start at position 0. Suppose you have Fred and Joe as candidates. Fred can be candidate[0] and Fred is candidate[1]. Then you can use them just as any other int. For example, to add one to the vote count for Fred, just do this:





candidate[1]=candidate[1]+1;





(Or shorter, candidate[1]++; )





There's more to arrays, but this should get you going.


No comments:

Post a Comment