This can't be your latest code - this fails to compile quite severely!
I've gone through it and here's what I have: you have no
function prototypes, the variables referenced in both functions
are declared in main so they cant be used, in district1 function
you have the word "do" where there should be a "while" and
lastly your code formatting is horrible!
Code:
#include <iostream>
using namespace std;
void district1(); //Need prototypes
void district2();
int main()
{
cout<<"Welcome to the election gizmo\n\n";
district1();
district2();
return 0;
}
void district1()
{
int voterNum = 1;
int candidateA = 0, candidateB = 0;
char choice;
cout<<"District 1 is first\n";
while (voterNum <= 10)
{
cout<<"Voter Number "<<voterNum<<" please vote now.\n";
cout<<"Your choices are candidate 'A' and candidate 'B'\n";
cout<<"Please enter your choice now: ";
cin>>choice;
if (choice=='A'||choice=='a')
{
candidateA++;
}
if (choice=='B'||choice=='b')
{
candidateB++;
}
cout<<endl<<voterNum<<" "<<candidateA<<" "<<candidateB<<endl;
voterNum++;
}
}
void district2()
{
int voterNum = 1;
int candidateA = 0, candidateB = 0;
char choice;
cout<<"District 2 is next\n";
while (voterNum <= 10)
{
cout<<"Voter Number "<<voterNum<<" please vote now.\n";
cout<<"Your choices are candidate 'A' and candidate 'B'\n";
cout<<"Please enter your choice now: ";
cin>>choice;
if (choice=='A'||choice=='a')
{
candidateA++;
}
if (choice=='B'||choice=='b')
{
candidateB++;
}
cout<<endl<<voterNum<<" "<<candidateA<<" "<<candidateB<<endl;
voterNum++;
}
}
thsi compiles but i fail to see the reason to have two functions
that perform identical tasks. Since this is c++ i'd make
an election class with district numbers, number of voters and
number of votes per candidate as private variables, then have
an election member function that performs the task that your
district functions perform, and then if main needs the results
of the election (which i assume it does, since it would be a fairly
insignificant program otherwise), write functions that return
the results. Just a suggestion