/* Andras Konya 9/23/01 Chapter 3 Exercise 16 --- Case Study Modified for Multi-Votes*/ #include #include int main () { cout << "-- Vote Analysis Program --" << endl << endl; apstring Candidate1, Candidate2; cout << "Enter the name of the first candidate: "; cin >> Candidate1; cout << "Enter the name of the second candidate: "; cin >> Candidate2; int Cand1York; cout << "Enter the votes from New York of " << Candidate1 << ": "; cin >> Cand1York; int Cand1Jers; cout << "Enter the votes from New Jersey of " << Candidate1 << ": "; cin >> Cand1Jers; int Cand1Conn; cout << "Enter the votes from Connecticut of " << Candidate1 << ": "; cin >> Cand1Conn; int Cand2York; cout << "Enter the votes from New York of " << Candidate2 << ": "; cin >> Cand2York; int Cand2Jers; cout << "Enter the votes from New Jersey of " << Candidate2 << ": "; cin >> Cand2Jers; int Cand2Conn; cout << "Enter the votes from Connecticut of " << Candidate2 << ": "; cin >> Cand2Conn; cout << endl; const long Cand1Votes = (Cand1York+Cand1Jers+Cand1Conn); const long Cand2Votes = (Cand2York+Cand2Jers+Cand2Conn); long VotesTotal = Cand1Votes + Cand2Votes; double Percent1 = 100 * double (Cand1Votes)/VotesTotal; double Percent2 = 100 * double (Cand2Votes)/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 cout.setf(ios::left); cout.width(ColWidth); cout << Candidate1; cout.setf(ios::right); cout.width(ColWidth); cout << Cand1Votes; cout.width(ColWidth); cout << Percent1 << endl; cout.setf(ios::left); cout.width(ColWidth); cout << Candidate2; cout.setf(ios::right); cout.width(ColWidth); cout << Cand2Votes; cout.width(ColWidth); cout << Percent2 << endl; cout.width(ColWidth); cout << "TOTAL: "; cout.width(ColWidth); cout << VotesTotal << endl; char dummy; cin >> dummy; return (0); }