Basic Tutorial Four (case)

In this tutorial you will once again modify the Rental Car program and just as in the last tutorial, you will be incorporating the variable controlled for/next loop for controlling the repetitive structure. As as in the last tutorial, you will use the Display Table Row Statements to display data in a table.
This tutorial introduces the select case/end select decision structure statements, which allows the program to decide what statements to do next, based on more than one possible value for a given variable. In this program you will use the select case statements to determine which of four Economy class categories the rental belongs to. A 'Gas Guzzler' gets 12 miles per gallon or less, and a 'Standard' car gets more than 12 up to a maximum of 30 miles per gallon. An 'Economy' car gets more than 30 miles per gallon, but less than a 'Green Machine' which gets 50 miles per gallon or more.
As in the previous tutorial, after all of the rentals have been listed, your program will print summary information including the number of rentals processed and the average mileage obtained by all vehicles reported.
Follow the steps outlined below to create and run this VBasic application.
Note: the BASIC Reference Guide can be download from this link. It identifies the VBasic instructions you will use coding in these four programs.

STEP 1 - Setting Up Your Browser and Notepad:

  • Using My Computer, locate the the BasicTutorialThree.html file you created in the last tutorial on your student data disk, and copy to the clipboard. Now paste it on your data disk and rename it as BasicTutorialFour.html.
  • Open BasicTutorialFour.html in your browser.
  • Now open the BasicTutorialFour.html document in Notepad.

STEP 2 - Enter Code Statements using Notepad:

  • Change the Browser title and the Report title lines to reflect Tutorial Four rather than Tutorial Three.
The program will no longer just display "Yes" or "No" in the last column. It will display one of four possible economy classes. Modify the code in the Print column heading section of your program so that the last column displays 'Economy Class' rather than 'Economy Rental'.
In the Compute values sections of your program replace the current if/else/end if code with the code to select the correct category based on the rental car's miles per gallon.

Note that the order of the tests (cases) is important , because the failure of the first case sets the minimum value for the second case. That is, a car with 15 miles per gallon will fail the first case ('are milesPerGallon less than or equal to 12?') so that when the program evaluates the next case ('are milesPerGallon less than or equal to 30') it already knows the milesPerGallon are greater than 12.

Also notice that the case else is used for that last possibility instead of an additional test.
select case true
    case milesPerGallon <= 12
      carMessage = "Gas Guzzler"
    case milesPerGallon <= 30
      carMessage = "Standard"
    case milesPerGallon <50
      carMessage = "Economy"
    case else
      carMessage = "Green Machine"
end select

Congrats!! You are done making modifications.

  • Go back and carefully check your typing
  • Click the 'Save' icon to save your changes

STEP 3 - Time to Test:

Test your program in your browser
  • When asked to enter data, use the following six cars to test your program:
Chevy with a starting odometer reading of 2300, an ending reading of 2742 and 8.5 gallons used.
Ford with a starting odomenter reading of 16507, an ending reading of 17200 and 46.2 gallons used
Dodge with a starting odometer reading of 14000, an ending reading of 14300 and 10 gallons used
Jeep with a starting odometer reading of 200, an ending reading of 600 and 32 gallons used
Toyota with a starting odometer reading of 1100, an ending reading of 14100 and 10 gallons used
Cadillac with a starting odometer reading of 4000, an ending reading of 4036 and 4 gallons used
Once you have entered the last requested data, and if you have coded your program correctly, your program will produce the written report on the monitor and end.

Be sure to verify the results with the image at the top of this tutorial.

STEP 4 - Documentation:

  • Print a copy of the page displayed on your browser and a copy of the source code from Notepad for your future reference
Return to 110 Examples Page