A pprogram that keeps reading positive numbers until the user enters a zero and print the smallest number
print "number: "; read value
smallest = value
while value ≠0
read value
if value < 0 then {print "Error: negative value"; continue}
if value < smallest then smallest = value
loop
if value > 0 then
print "Smallest: ",smallest
else
print "No values entered."
endif
To write a program that keeps reading positive numbers until the user enters zero and then prints the smallest number, you can use a simple algorithm:
1. Initialize a variable called `smallest` to a very large number, such as `float('inf')`, so that any positive number entered by the user will be smaller than `smallest`.
2. Start an infinite loop that will continuously read user input until a zero is entered.
3. Inside the loop, prompt the user to enter a positive number.
4. Convert the user input to a number and assign it to a variable, let's say `number`.
5. Check if `number` is smaller than `smallest`. If it is, update the value of `smallest` to `number`.
6. Check if `number` equals zero. If it does, break out of the loop to end the program.
7. Repeat steps 3-6 until the loop is exited.
8. After the loop ends (i.e., when a zero is entered), print `smallest` as the smallest number entered by the user.
Here's an example implementation in Python:
```python
smallest = float('inf')
while True:
number = float(input("Enter a positive number (enter 0 to stop): "))
if number < smallest:
smallest = number
if number == 0:
break
print("The smallest number entered was:", smallest)
```
By running this program, you can keep entering positive numbers until you enter zero, and it will display the smallest number among the positive numbers entered.