medal..... c++ program...needed You are required to write a program in which the program will ask the user to enter Lower limit and Upper limit for a loop. It means that loop will start from the lower limit and will execute till the upper limit. After taking the input, the program should show the sum of all the numbers from lower limit to upper limit in each iteration of the loop. For example if the user enters 3 as lower limit and 8 as upper limit. The output should be as: 3 7 12 18 25 33 What you are doing here is you are adding the lower limit into the number next to it and showing it in the same iteration. Also the program will count the even and odd numbers in the output. In this example, the count of the even numbers will be 2 and the odd numbers will be 4. So the final output would be Sample Output: Enter the lower limit for the loop: 3 Enter the upper limit for the loop: 8 3 7 12 18 25 33 Even numbers: 2 Odd numbers: 4
A little ugly, but oh well. I wrote comments and tried to keep simple, so I hope it's clear, but feel free to ask questions http://ideone.com/7mtw3I
class EOF_Exception : public exception {}; why you used this?
Because the input is given through standard input (stdin) and therefore it has to handle the situation when End Of File (EOF) is received (which notifies that no more input is about to come). That pretty much causes the stream to close and for `cin` to stop from listening. That means that if the user were to send EOF to the program (usually using ctrl+D) instead of giving a number, without handling this it would freak out trying to get valid numbers in a loop and failing immediately, as reading through `cin` just fails... I use this class for throwing an exception indicating that EOF was received and when it is catched in the `main` function it just closes gracefully.
thx
sure
Join our real-time social learning platform and learn together with your friends!