Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. using namespace std;
  5. int main() {
  6. //start
  7. int n;
  8. cout << "number of candidates: ";
  9. cin >> n;
  10. system("cls");
  11.  
  12. //screen 1
  13. string name[n];
  14. float votes[n];
  15. float totalSum = 0;
  16. int i;
  17. int CNo = 1;
  18.  
  19. cin.ignore();
  20. cout << "Voting System" << endl;
  21. for (i = 0; i < n; i++) {
  22. cout << "Candidate " << CNo << ": ";
  23. CNo++;
  24. getline(cin, name[i]);
  25. cout << "Votes: ";
  26. cin >> votes[i];
  27. cin.ignore();
  28. }for (i = 0; i < n; i++) {
  29. totalSum += votes[i];
  30. }
  31. system("cls");
  32. //screen 2
  33. CNo = 1;
  34. for (i = 0; i < n; i++) {
  35. float percent = votes[i] / totalSum * 100;
  36. cout << "Candidate " << CNo << ": " << name[i] << "\t\t" << "Votes: " << votes[i] <<"\t\t" << setprecision(2)<< "Percentage: " << percent << "%" << endl;
  37. CNo++;
  38. }cout << "Continue? (Y/N)" << endl;
  39. ;
  40. //input for Continue
  41. char q;
  42. cin >> q;
  43. if(q == 'Y' || q == 'y'){
  44. goto Continue;
  45. }else{
  46. exit(0);
  47. }Continue:
  48. cout << "SUMMARY" << endl;
  49. cout << "Number of Votes = " << totalSum << endl;
  50. ;
  51.  
  52. for(i = 0; i < n; i++){
  53. for(int j = 1 + 1; j < n; j++){
  54. if(votes[i] < votes[j]){
  55. float temp = votes[i];
  56. string temp2 = name[i];
  57. votes[i] = votes[j];
  58. name[i] = name[j];
  59. votes[j] = temp;
  60. name[j] = temp;
  61. }
  62. }
  63. }cout << "top 3 Voters Choice: " << endl;
  64. int choice = 0;
  65. for(i = 0; i < 3; i++){
  66. cout << i << ". " << name[choice] << "Votes = " << votes[choice];
  67. choice++;
  68. }
  69.  
  70. system("pause");
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement