84 673
Assignments Done
99,1%
Successfully Done
In March 2020

# Answer to Question #13980 in C++ for mac eleazar

Question #13980
write a C++ program for Presidential Elections, the user will enter his votes based on the code for each candidate. The program will add the total votes for each candidate and proclaim the winner whoever got the most number of votes. The user will in accepting votes if the user enterde letter &#039;Q&#039;, &#039;V&#039; to vote &#039;R&#039; to view the result.
1
2012-08-31T08:06:18-0400
#include <iostream>
using namespace std;

void Result(char candidates[][20], int *results);

int main()
{
char candidates[4][20] = {"Candidate1","Candidate2","Candidate3","Candidate4"};
int results[4] = {0};
while(true)
{
cout<<"Select one item: ";
char choice;
cin>>choice;
switch(tolower(choice))
{
case 'q':
";
return 0;
break;
case 'r':
cout<<"
Temporary results:
";
Result(candidates,results);
break;
case 'v':
cout<<"Enter candidate number: ";
int n;
cin>>n;
results[n-1]++;
break;
}
cout<<endl;
}
return 0;
}

{

cout<<"V - vote"<<endl;
cout<<"R - view results"<<endl;
cout<<"Q - quit"<<endl;
}

void Result(char candidates[][20], int
*results)
{
cout<<"
Results:
";
for (int i=0;i<4;i++)
{
cout<<i+1<<". "<<candidates[i]<<" "<<results[i]<<endl;
}
}
{
int max=0;
for (int i=1;i<4;i++)
{
if (arrcandidates[i]>arrcandidates[max])
max = i;
}
return max;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!