The first Basic statement you will alter is the comment statement that has Sue Chen's name on it
(e.g. rem written by Sue Chen)
-
Change Sue's name to yours
|
Variables are used to "remember" data entered into the program. You will need to declare variables for
the four data items requested from the user and the two data items your program will compute. You will
also need a variable to hold the economy rental message
-
Enter the following statements immediately following the comment statement "rem Declare Variables"
dim carType
|
dim startMiles
|
dim endMiles
|
dim gallonsUsed
|
dim totalMiles
|
dim milesPerGallon
|
dim carMessage
|
|
You will now need to code the Display on a single line statement to display a report title line that will
identify the author and the tutorial problem. Each of the two pieces of the report title are enclosed in quotes
and separated by the ampersand (&) symbol. The <br> code in the second piece of the document.write()
statement is html code that will force the computer to skip down a line after displaying the report title.
-
After the comment statement "rem Print report title", enter the document.write() statement
with your name as below:
document.write("Sue Chen - Basic Tutorial One" & "<br>")
|
|
You will need to enter the code to get the user input using the Assign Input Data statements. Character data
must be converted using the cstr() function. Numeric integers require the cint() conversion function,
and numbers with decimals will use the csng() function.
-
Enter the following assign input data statements after the comment statement "rem Get user input data" being
very careful to correctly enter the required parenthesis and quotes. Typing errors can cause the scripts to not run!
carType = cstr(inputbox("Enter make of car"))
|
startMiles = cint(inputbox("Enter beginning odometer reading"))
|
endMiles = cint(inputbox("Enter ending odometer reading"))
|
gallonsUsed = csng(inputbox("How many gallons?"))
|
|
-
After the comment statement "rem Compute values", you need to compute the total miles and miles per gallon using the
Assign statements:
totalMiles = endMiles - startMiles
|
milesPerGallon = totalMiles / gallonsUsed
|
-
Also in the Compute values section of the program, add the if/else/end if statement to determine the value of the
carMessage variable. This must be done after the milesPerGallon calculation:
if milesPerGallon >30 then
|
carMessage = "Yes"
|
else
|
carMessage = "No"
|
end if
|
|
-
In the Print detail lines section, enter the code to display the make of car, total miles, miles per gallon, and whether or not
the rental is an Economy car, each on a separate line.
-
Be very careful with your typing. A missing quote or parenthesis could cause a scripting error. Also be sure to include a space after
the colon (:) and before the closing quotes (" ") on the labels. Otherwise Make of car: Chevy
will appear incorrectly as Make of car:Chevy
document.write("Make of car: " & carType & "<br>")
|
document.write("Total miles: " & totalMiles & "<br>")
|
document.write("Miles per gallon: " & milesPerGallon & "<br>")
|
document.write("Economy rental: " & carMessage & "<br>")
|
|
-
Go back and carefully check your typing
-
Click the 'Save' icon to save your changes
|