Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A nice characteristic of this problem is that it can be developed in small pieces. Remember: always try to break a problem into smaller pieces

A nice characteristic of this problem is that it can be developed in small pieces. Remember:
always try to break a problem into smaller pieces that are easier to solve.
b) First write a program that prompts for an integer, displays the integer, and stops asking for more
integers when 0 is entered. Use while. Under what condition do you continue to loop? Here is a
suggested outline:
prompt for an integer # (and convert the string to an int)
while some_Boolean_condition:
# do something
prompt for another integer
c) Once that simple program is tested and working, add in another piece such as (c) to count the
number of odd integers entered. Create a variable with an appropriate name, such as
odd_count, and assign it an initial value of 0(before the while loop). When an odd number is
entered, add one to odd_count (for example, odd_count +=1). Display the count.
d) Next: count the number of even integers and display the count.
e) Next: calculate the sum of the odd integers. The approach is similar to counting: choose a
variable name, initialize it to 0; when the integer is odd, add the integer to the variable. Display
the sum.
f) Next: calculate the sum of the even integers and display the sum.
g) Finally, ignore all negative numbers which the user inputs. One approach: if the integer is
positive, do all the counting and summing, else do nothing (that is, you can use an if statement
without an else clause).
h) If you have time, try this: print a message if the integer is negative.

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

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions