(Sequencing, Variables, Data Types & Arithmetic)
When you see a flash of lightning and hear thunder afterwards, the delay between the flash and the sound can be used to estimate how far away the lightning was. Sound travels through air at approximately 343 metres per second.
You are going to create a simple program to estimate the distance to the source of a sound.
Write a program that:
Example:
Welcome to the Sound Distance Calculator!
Use a real/float variable:
Example:
Enter the time delay in seconds:
Store this as a real/float.
Use an arithmetic formula:
This gives the distance in metres.
For example:
The sound source is approximately 686 metres away.
Make sure the output is clear and uses the correct data type formatting.
Declaring variables
Choosing data types (integer vs real)
Sequencing instructions correctly
Performing arithmetic
Input/output
Convert the distance into kilometres.
Ask the user for the temperature and adjust the speed of sound using:
speed = 331 + 0.6 × temperature
Format the output to 2 decimal places.
Display the distance in both metres and kilometres.