Question
A democrat and a republican are running for an open seat in the House of Representatives. In an exit poll voters are asked which candidate
A democrat and a republican are running for an open seat in the House of Representatives. In an exit poll voters are asked which candidate they voted for. We want a program to calculate what percentage of votes each candidate received. We will do this in two steps (Submit ONE final program)
(a) Write a program to do the following. It asks the data entry clerk to enter which candidate each voter voted for. If the voter voted for the democrat, enter the letter D. If the voter voted for the republican, enter the letter R. If the voter voted for anybody else, enter the letter O. The program should use a while loopto asks for the votes one by one. When there is no more votes to enter, Q will be entered to terminate the loop. Dont count anything yet. Simply ask for the votes with a while loop. Remember that the user may enter uppercase or lowercase letters. Your program should be able to handle both. (10 points)
(b) Modify the program in part (a) so that it will do the following using a switch statement: (10 points)
(1) counts and display the number of votes the democrat candidate received
(2) counts and display the number of votes the republican candidate received
(3) counts and display the number of votes other candidates received, i.e. the number of times O or o is entered
(4) calculate and display what percentage of total votes each candidate received (democrat, republican, and others)
MAKE SURE TO INCLUDE A SWITCH STATEMENT!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started