Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab Procedure: 1. Prior starting of the work consider how to design the while loop: a. What would be the loop condition? b. What would
Lab Procedure: 1. Prior starting of the work consider how to design the while loop: a. What would be the loop condition? b. What would be the stopping criteria? 2. Determine how to calculate the summation and average of the even and odd numbers separately. What are the variables to store the summations and where to initialize the variables? Hint: define a variable named 'total_even' for even numbers and 'total_odd' for odd numbers, initialize them with a value of 0 before while loop and keep adding the even numbers to 'total_even' and the odd numbers to 'total_odd'. Think about the right operator which keeps adding to a variable and the right operator which identify a number is even or odd. 3. How to calculate the average (formula provided below) of even and odd numbers separately? How to obtain the total number of even numbers and the total number of odd numbers. Hint: Think about the variables 'count_odd' and 'count_even'. Average of even numbers = summation of even numbers / total number of even numbers Average of odd numbers = summation of odd numbers / total number of odd numbers 4. Test the application by hand-calculating several values and use the same values to validate the operation. Your code is supposed to calculate the summation and average of even and odd numbers as shown below. Also, don't count " 0 " as an even number when you calculate the average of even numbers. Sample input/output: Enter a non-zero number or type 0 to exit: 8 Enter a non-zero number or type 0 to exit: 20 Enter a non-zero number or type 0 to exit: 15 Enter a non-zero number or type 0 to exit: 50 Enter a non-zero number or type 0 to exit: 35 Enter a non-zero number or type 0 to exit: 5 Enter a non-zero number or type 0 to exit: 42 Enter a non-zero number or type 0 to exit: 0 Summation of even numbers: 80 Summation of odd numbers: 45 Average of even numbers: 20.0 Average of odd numbers: 15.0
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