Question
Make a flowchart of the following program #include #include using namespace std; int main() { int voteCounts[5] = {0}; // array to store vote counts
Make a flowchart of the following program
#include
#include
using namespace std;
int main() {
int voteCounts[5] = {0}; // array to store vote counts for each candidate
int totalVotes = 0; // counter for total number of votes
cout << "Enter the votes (1-5), one per line (enter 0 to end): ";
int vote;
cin >> vote;
while (vote != 0) {
if (vote >= 1 && vote <= 5) { // check if vote is valid
voteCounts[vote -
1]++; // increment vote count for corresponding candidate
totalVotes++; // increment total vote count
}
cin >> vote; // read in next vote
}
// calculate and display results
cout << "Results: ";
for (int i = 0; i < 5; i++) {
int candidateNumber = i + 1;
double percentage = (double)voteCounts[i] / totalVotes * 100;
cout << "Candidate " << candidateNumber << ": " << voteCounts[i]
<< " votes (" << fixed << setprecision(2) << percentage << "%)"
<< endl;
}
cout << "Total votes: " << totalVotes << endl;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started