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 total distance in miles.
Write code to convert the distance entered into kilomet... 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
First, obtain the value entered in the text box, ensuring to convert it to an integer since it represents the distance in miles.
Step 2
Convert miles 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
Using the formula for conversion, apply the calculation as follows:
Distancekm=Distancemiles∗1.6
Step 3
Display the distance in the 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
Ensure that the output clearly shows the distance converted into kilometers along with appropriate labeling to inform the user of what the value represents.