Write a complete program that: 1. Uses a do... while loop to prompt the user to enter a count that is greater than 1 and less than or equal to 10000 then reads in a count from the keyboard as an integer. a. If input error occurs or the count the user enters is less than or equal to 1 or greater than 10000, output an error. After outputting an error clear/ignore the failed input and continue do... while looping until a valid number is entered. 2. Uses a for loop to find the sum of all of the even numbers from 1 to the number input in (1). 3. Uses a while loop to find the sum of all of the odd numbers from 1 to the number input in (1). Your program must handle the possibility that the user accidentally enters a character or out of bounds number. If a character or an out of bounds number is entered, the stream should be cleared, any previous values read should be discarded, an error displayed, and the user prompted again. The program should not exit until good values have been entered.
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images