Write a C++ program that calculates the sum of natural numbers from 1 to N (inclusive), where N is a positive integer. Implement custom exception handling to ensure that negative input is not accepted. If a negative number is entered, display "Negative or zero input is not allowed. Please enter a positive integer." an error message and request a positive input.
Exception Handling
Sum of natural numbers
Report a typo
Sample Input 1:
3Sample Output 1:
6Sample Input 2:
-3Sample Output 2:
Error: Negative or zero input is not allowed. Please enter a positive integer.Sample Input 3:
4Sample Output 3:
10Write a program in C++
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.