Answered step by step
Verified Expert Solution
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 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 someBooleancondition:
# 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
oddcount, and assign it an initial value of before the while loop When an odd number is
entered, add one to oddcount for example, oddcount 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 ; 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
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