Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Multidimensional Array Data Management In Databases

Authors: Florin Rusu

1st Edition

1638281483, 978-1638281481

More Books

Students also viewed these Databases questions

Question

Design a job advertisement.

Answered: 1 week ago