Distance as displayed in miles on some road maps - NSC Information Technology - Question 1 - 2016 - Paper 1
Question 1
Distance as displayed in miles on some road maps. The user is required to enter the distance in miles in the text box.
Write code to convert the distance entered in... show full transcript
Worked Solution & Example Answer:Distance as displayed in miles on some road maps - NSC Information Technology - Question 1 - 2016 - Paper 1
Step 1
Extract the distance from the text box as an integer
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Use the appropriate method to retrieve the distance from the input field and store it as an integer value.
Step 2
Convert distance to kilometers
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The formula for conversion is:
Distanceext(km)=Distanceext(miles)imes1.6.
Step 3
Display the distance in text box with labels
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Format the output to show both the distance in kilometers and the relevant label, ensuring clear readability for users.