Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- int main() {
- //start
- int n;
- cout << "number of candidates: ";
- cin >> n;
- system("cls");
- //screen 1
- string name[n];
- float votes[n];
- float totalSum = 0;
- int i;
- int CNo = 1;
- cin.ignore();
- cout << "Voting System" << endl;
- for (i = 0; i < n; i++) {
- cout << "Candidate " << CNo << ": ";
- CNo++;
- getline(cin, name[i]);
- cout << "Votes: ";
- cin >> votes[i];
- cin.ignore();
- }for (i = 0; i < n; i++) {
- totalSum += votes[i];
- }
- system("cls");
- //screen 2
- CNo = 1;
- for (i = 0; i < n; i++) {
- float percent = votes[i] / totalSum * 100;
- cout << "Candidate " << CNo << ": " << name[i] << "\t\t" << "Votes: " << votes[i] <<"\t\t" << setprecision(2)<< "Percentage: " << percent << "%" << endl;
- CNo++;
- }cout << "Continue? (Y/N)" << endl;
- ;
- //input for Continue
- char q;
- cin >> q;
- if(q == 'Y' || q == 'y'){
- goto Continue;
- }else{
- exit(0);
- }Continue:
- cout << "SUMMARY" << endl;
- cout << "Number of Votes = " << totalSum << endl;
- ;
- for(i = 0; i < n; i++){
- for(int j = 1 + 1; j < n; j++){
- if(votes[i] < votes[j]){
- float temp = votes[i];
- string temp2 = name[i];
- votes[i] = votes[j];
- name[i] = name[j];
- votes[j] = temp;
- name[j] = temp;
- }
- }
- }cout << "top 3 Voters Choice: " << endl;
- int choice = 0;
- for(i = 0; i < 3; i++){
- cout << i << ". " << name[choice] << "Votes = " << votes[choice];
- choice++;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement