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 'Q', 'V' to vote 'R' to view the result.
1
Expert's answer
2012-08-31T08:06:18-0400
#include <iostream> using namespace std;
void Menu(); void Result(char candidates[][20], int *results); int SelectMaxVotes(int *arrcandidates);
int main() { char candidates[4][20] = {"Candidate1","Candidate2","Candidate3","Candidate4"}; int results[4] = {0}; while(true) { Menu(); cout<<"Select one item: "; char choice; cin>>choice; switch(tolower(choice)) { case 'q': cout<<"The winner is "<<candidates[SelectMaxVotes(results)]<<"! "; 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; }
Comments
Leave a comment