Question: Question 1 [ 3 mark ] Find the Smallest Number Write a simple program that helps a user find the smallest positive number among a

Question 1[3 mark] Find the Smallest Number
Write a simple program that helps a user find the smallest positive number among
a limited series of positive integers entered by the user. The program should
perform the following tasks:
1. Prompt the user to enter a series of positive integers: The program should
repeatedly prompt the user to enter up to 5 positive integers, separated by
blanks. The user can enter no more than 5 positive integers, and to indicate
the end of input, the user should enter -1. The program will omit the integers
after -1.
Wrong Condition 1: If the user enters a non-positive integer
(excluding -1), display an error message and terminate the program.
The program should not consider negative integers.
Example: -2341-1 Note: -2 is a non-positive integer before ending
Example: 0341-1 Note: 0 is a non-positive integer before ending
Example: 3-4-1 Note: -4 is a non-positive integer before ending
Example: 32-4-1 Note: -4 is a non-positive integer before ending
Example: 32-49-1 Note: -4 is a non-positive integer before ending
For these examples, the program display:
Wrong Condition 2: If the user enters a non-integer value (e.g., a
letter or a symbol), display an error message and terminate the
program. The program should not consider this input.
Example: 5 B C 2-1 Note: B is a non-integer value before ending
Example: B 2-1 Note: B is a non-integer value before ending
Example: $ 14-1 Note: $ is a non-integer value before ending
Example: A 5 B C 2-1 Note: A is a non-integer value before ending
Example: 5241 & -1 Note: & is a non-integer value before ending
For these examples, the program display:
Error: Non-positive integer.
Thank you for using the program!
Error: Not ended with -1.
Thank you for using the program!
Wrong Condition 3: If the user only enters -1 or the first integer is -
1, display an error message and terminate the program.
Example: -1 Note: only enters -1
Example: -1253 Note: the first integer is -1
For these two examples, the program display:
Wrong Condition 4: If the number of positive numbers is more than
5 before the ending -1, display an error message and terminate the
program.
Example:654321-1 Note: the number of positive numbers is
more than 5 before the ending -1.
Example: 34253423-1 Note: the number of positive numbers is
more than 5 before the ending -1.
For these two examples, the program display:
The program will only report the first error it meets.
Example: -2 A 152025-1 Note: the first error is non-positive integer.
For this example, the program display:
Error: Non-positive integer.
Thank you for using the program!
Error: Only -1.
Thank you for using the program!
Error: Non-integer value.
Thank you for using the program!
2. Find the smallest positive number: After the user finishes entering feasible
numbers and enters -1 to stop, the program should determine the smallest
positive number from the entered values.
3. Display the smallest positive number: The program should display the
smallest positive number to the user.
4. Ask the user if they want to repeat the process: After displaying the
smallest positive number, the program should ask the user if they want to
find the smallest positive number again with a new series of positive
integers. If the user responds with "Y", repeat the process. If the user
responds with "N", end the program. Other responses, such "abc" and "aaa",
will also end the program (Please refer to the Example 5 below).
The examples have considered most cases for test. Please carefully read the
examples, which will help you to fully understand the above question.
Ensure that the program output follows the format of the following examples.
Otherwise, you will not pass the test.
For example, Enter up to 5 positive integers, separated by blanks. To stop,
enter -1 and press Enter:. You should not misspell any words. A good
strategy is to directly copy the sentence and use it in your program.
Example 1
Enter up to 5 positive integers, separated by blanks. To stop, enter -1 and press Enter:
101520-1
The smallest positive number is: 10
Do you want to find the smallest positive number again? (Y/N):
Y
Enter up to 5 positive integers, separated by blanks. To stop, enter -1 and press Enter:
58121822-1
The smallest positive number is: 5
Do you want to find the smallest positive number again? (Y/N):
N
Thank you for using the program!
Example 2
Example 3
Example 4
Example 5
Example 6
Enter up to 5 positive integers, separated by blanks. To stop, enter -1 and press Enter:
-1
Error: Only -1.
Thank you for using the program!
Enter up to 5 positive integers, separated by blanks. To stop, enter -1 and press Enter:
17-1
The smallest positive number is: 17

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!