# Software Engineering programming do while loop

1. I need to create a program where the user inputs height - program asks for if the user wants to input more heights? if yes you program loops back to the start - if not, drops out and gives the average of heights and asks the user if they want to continue or terminate the program??? I'm still new to the programming world, any help would be great
2. Hi smorgan594,

I am wondering what programming language you would like to do this in?

As an example we can simply put this into Python code:

We could go about stating this programs objectives:
1. Allow a user to enter in their desired heights and save these temporarily,
2. If the user was to stop entry, all the saved heights would be used to calculate an average.

NOTE: The indentation in the code below is incorrect, I am unsure how to properly indent code on posts, hopefully this can help.

heights = [] # An empty list; this is where can temporarily store our heights the user enters in.

# This procedure will allow you to calculate the mean of the heights.
def calculate_average(heights):
sum_heights = 0 # Store the sum of the heights.

# This is a for loop to iterate through the items in the heights list and return the mean of the list.
for height in heights:
sum += height # Add the value of height to the sum.

mean = sum_heights / len(heights) # Divide the sum by the length of the heights, giving us our mean.
return mean # Return the mean to use.

while True: # This will start a continuous loop in Python.
entered_height = float(input('Enter the height you require: ' # Get the entry of the user as a string, then convert it into # a floating point decimal.
heights.append(entered_height) # This will add the height, as a decimal, to the list.
more_heights = input('Do you want to input more heights (Y/N)?'
if more_heights is 'Y':
continue # starts the loop again.
elif more_heights is 'N':
average_height = calculate_average(heights) # Calculate an average using our function and then store it. print('Average height from the data you entered:', average_height)
terminate = input('Terminate program? (Y/N)')
if terminate is 'Y':
break # Stops the while loop and as a result the program terminates due to no more code.
elif terminate is 'N':
continue # Continues with the main while loop.

## Register

Thanks for posting! You just need to create an account in order to submit the post
1. this can't be left blank
2. this can't be left blank
3. this can't be left blank

6 characters or longer with both numbers and letters is safer

4. this can't be left empty
1. Oops, you need to agree to our Ts&Cs to register

Updated: October 14, 2016
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Today on TSR

### Haven't started revising yet?

It's not too late!

### My mum and BFF's mum are having an affair

Poll
Study resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.