Advertisement
Guest User

Untitled

a guest
May 1st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. string name[5];
  11. double votes[5];
  12. double percent;
  13. int entry = 0;
  14. int total = 0;
  15.  
  16. do {
  17. cout << "Enter candidate number " << entry+1 << "'s last name\n:";
  18. cin >> name[entry];
  19. entry++;
  20. } while (entry < 5);
  21.  
  22. cout << endl;
  23. entry = 0;
  24. do {
  25. cout << "Enter candidate " << name[entry] << "'s votes\n:";
  26. cin >> votes[entry];
  27. entry++;
  28. } while (entry < 5);
  29.  
  30. cout << endl;
  31.  
  32.  
  33. entry = 0;
  34. do {
  35. total += votes[entry];
  36. entry++;
  37. } while (entry < 5);
  38.  
  39. cout << "Here are the results for this election:\n\nCandidate" << " " << "Votes" << " " << "Percent\n";
  40. entry = 0;
  41. do {
  42. cout << setw(14) << left << name[entry] << setw(8) << setprecision(0) << fixed << votes[entry];
  43. percent = (votes[entry] / total) * 100;
  44. cout << setprecision(2) << fixed << percent;
  45. cout << endl;
  46. entry++;
  47. } while (entry < 5);
  48. cout << endl;
  49. cout << "Total votes: " << total;
  50. cout << endl;
  51. system("pause");
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement