Question
C++ Please write a snippet of code executing a loop which: 1. processes a series of numeric inputs and sum up the square of the
C++
Please write a snippet of code executing a loop which:
1. processes a series of numeric inputs and sum up the square of the each input: ?in?number2
3. uses any non-numeric input as sentinel for terminating input data
2. contains a flag (bool input_started) which is to be set inside the loop to indicate the loop has started, even when there is no valid data entered at all, i.e. the first input is non-numeric
4. has all of the statements which process the inputs located inside the loop only, including the one(s) which prompts for the all the inputs (cout)
5. declares some variables outside of the loop, naturally
6. doesn't use array, not necessary.
Hint: there are more than one way to implement, but only the efficient ones presented will receive full credit. Before coding, please think about all the available forms of loop and which one is the best choice for this problem. You also have to consider what essential variable(s), the types and so forth, need to be created for tracking the loop, and other local variables for the input value and computation result. If your solution is not complete but make some sense, you will get partial credit. Coding style and nomenclature compliance are not required for this question.
Here is a sample output:
enter a new input number, type any non-numeric key to end data input: 1 enter a new input number, type any non-numeric key to end data input: 2 enter a new input number, type any non-numeric key to end data input: 2.5 enter a new input number, type any non-numeric key to end data input: q sum of sq: 11.25 Press any key to continue . . .
? in. number,2Step 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