Question: Update this code so that it enforces the following rules: - each entered value must be 0 or more - ensures that republicanVotes and democraticVotes

Update this code so that it enforces the following rules: - each entered value must be 0 or more - ensures that republicanVotes and democraticVotes add up to the value entered for totalVoters. Loop and re-prompt until the values are all valid. - ensures that the "don't make sense" message is never printed because it re-prompts for input when the numerical values entered don't make sense. 
 // Electoral College #include  using namespace std; 

int main() { int totalVoters; int republicanVotes, democraticVotes; cout << "How many Electoral College electors are there? "; cin >> totalVoters; cout << "How many of these electors voted for the Republican party candidate? "; cin >> republicanVotes; cout << "How many of these electors voted for the Democratic party candidate? "; cin >> democraticVotes; double pctRepub = ( 100.0 * republicanVotes ) / totalVoters; double pctDemoc = ( 100.0 * democraticVotes ) / totalVoters; cout.setf(ios::fixed); // see pp. 30-31 in Savitch book cout.precision(1); cout << endl; cout << pctRepub << "% of the " << totalVoters << " electors voted for the Republican party candidate." << endl; cout << pctDemoc << "% of the " << totalVoters << " electors voted for the Democratic party candidate." << endl; cout << endl; if (pctRepub > pctDemoc) { cout << "Looks like the Republican party candidate won!" << endl; } if (pctDemoc > pctRepub) { cout << "Looks like the Democratic party candidate won!" << endl; } if (republicanVotes + democraticVotes != totalVoters) { cout << "Looks like some of these data values don't make sense." << endl; } return(0); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!