/* Andras Konya 9/23/01 Chapter 3 Review 15 --- Case Study with 3 Candidates*/ #include #include int main () { cout << "-- Vote Analysis Program --" << endl << endl; apstring Candidate1, Candidate2, Candidate3; // defines candidates cout << "Enter the name of the first candidate: "; cin >> Candidate1; cout << "Enter the name of the second candidate: "; cin >> Candidate2; cout << "Enter the name of the third candidate: "; cin >> Candidate3; long Votes1, Votes2, Votes3; // defines votes for cout << "Enter the votes for " << Candidate1 << ": "; // each candidate cin >> Votes1; cout << "Enter the votes for " << Candidate2 << ": "; cin >> Votes2; cout << "Enter the votes for " << Candidate3 << ": "; cin >> Votes3; cout << endl; long VotesTotal = Votes1 + Votes2 + Votes3; double Percent1 = 100 * double (Votes1)/VotesTotal; // gets percent for double Percent2 = 100 * double (Votes2)/VotesTotal; // each candidate double Percent3 = 100 * double (Votes3)/VotesTotal; const int ColWidth = 10; //Width of columns in table cout.setf(ios::fixed); cout.precision(2); // Output column headings cout.setf(ios::left); cout.width(ColWidth); cout << "Candidate"; cout.setf(ios::right); cout.width(ColWidth); cout << "Votes"; cout.width(ColWidth); cout << "Percent" << endl; // Output Election Results // Candidate 1 cout.setf(ios::left); cout.width(ColWidth); cout << Candidate1; cout.setf(ios::right); cout.width(ColWidth); cout << Votes1; cout.width(ColWidth); cout << Percent1 << endl; // Candidate 2 cout.setf(ios::left); cout.width(ColWidth); cout << Candidate2; cout.setf(ios::right); cout.width(ColWidth); cout << Votes2; cout.width(ColWidth); cout << Percent2 << endl; // Candidate 3 cout.setf(ios::left); cout.width(ColWidth); cout << Candidate3; cout.setf(ios::right); cout.width(ColWidth); cout << Votes3; cout.width(ColWidth); cout << Percent3 << endl; // Total Votes Display cout.width(ColWidth); cout << "TOTAL: "; cout.width(ColWidth); cout << VotesTotal << endl; char dummy; cin >> dummy; return (0); }