Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions: Write an application called EvenOrOddCounter that prompts the user for integer numbers and counts how many of the numbers entered were even and how

Instructions: Write an application called EvenOrOddCounter that prompts the user for integer numbers and counts how many of the numbers entered were even and how many were odd until a 0 is entered. There is additional information about while loops with sentinels at the end of this document. Your program should: use a while loop prompt the user to enter a integer values until a 0 is entered your codes prompt must resemble the examples below determine if the value is even or odd. Hint: when even numbers are divided by 2 the remainder is 0 count the number of even values entered and the number of odd values entered display results as shown in the example below if the user enters a 0 for the first number, indicate that no values were entered Listed below are two example outputs. Of course, your output can be different depending on the values entered. Example 1: Even or Odd Counter ---------------------- Please enter a series of integer values. 0 to quit. Enter value 1: 34 Enter value 2: -2 Enter value 3: 3 Enter value 4: 0 The Results ----------- Total values entered: 3 Even values entered : 2 Odd values entered : 1 Example 2: Even or Odd Counter ---------------------- Please enter a series of integer values. 0 to quit. Enter value 1: 0 The Results ----------- No Values were entered. More information about while loops and sentinels Sometimes we dont know in advance how many values will be entered by the user. In a situation such as this, we ask the user to enter a sentinel value to indicate that no more values will be entered. When a user enters the sentinel, the loop terminates. This assignment is an example of using a sentinel to signal that there are no more values to be entered. In this assignment 0 is the sentinel value. The following is an outline of the general structure of using a while loop with a sentinel. initialize variables read the first value from the user //priming read while (value != sentinel) { determine if the value is even or odd increment the appropriate counter do any other work read the next value from the user //update read } report out results

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_2

Step: 3

blur-text-image_3

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

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

Explain Coulomb's law with an example

Answered: 1 week ago

Question

What is operating system?

Answered: 1 week ago

Question

What is Ohm's law and also tell about Snell's law?

Answered: 1 week ago