Question
Lab Assignment 1. Even sum. Study hovering. As you work on this project, demonstrate to the lab instructor looking up the value of a variable
Lab Assignment
1. Even sum. Study hovering. As you work on this project, demonstrate to the lab instructor looking up the value of a variable by hovering over it. Create a project titled Lab3_Sum with a single file sum.cpp. Your program should ask the user for a sequence of numbers until the user inputs 0 (zero) and then the program should print the sum of even numbers that the user input. Here is an example dialog:
Input sequence of integers (zero to stop): -4 3 -20 10 45 100 -1 0
The sum of even numbers is: 86
You are not allowed to use functions, arrays or other constructs that we have not yet studied. Hint: You need to use iterate-and-keep-track idiom. while or do-while would be a good construct to use. Consider a single number in each iteration. In the while-expression check if this number is not zero. If not -- proceed, if yes -- stop evaluation and print out the result. Declare a variable where your program will collect the sum. Make sure to initialize this variable. In the loop, with an if, check if the number is even and, if yes, add it to the sum. Look at this example of selecting the maximum number. It is very similar to what you need to implement. Also, integer division or the remainder operator are quite helpful.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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