Car Dealership Problem
A local car dealership needs to know at the end of the week, the total number of vehicles sold. They keep a record of each day's sales. Besides the weekly total they also need to know the average number sold per day. They will run your program Saturday night at closing and will provide you with the total sold for each day of the week.
Problem Statement:
Assumptions: (These help us establish the scope of the problem
(what we will and will not be doing)
1. Vehicle type is not provided <-- We
assume this so that we know we will not asking for vehicle types.
2. Only one dealership at a time <--- We want to
ensure they don't want us to total up more than one dealership
3. Only one week's information will be processed. <---Ensuring that
we are not going to be also figuring out the monthly/yearly total
4. Number of days is always 7 with calculations based on 7 days. If
they are closed or do not sell any cars then that day will be treated a zero.
Input:
1. Sunday Total
2. Monday Total
3. Tuesday Total
4. Wednesday Total
5. Thursday Total
6. Friday Total
7. Saturday Total
Calculations:
1. Grand Total = Sunday Total + Monday Total + Tuesday Total +
Wednesday Total + Thursday Total + Friday Total + Saturday Total
2. Dealership Average = Grand Total/ number of days
Output:
1. The weekly total is "Grand Total"
2. The daily average is "dealership Average"
Human Algorithm:
1. Number of days = 7
2. Ask for Sunday Total
3. Ask for Monday Total
4. Ask for Tuesday Total
5. Ask for Wednesday Total
6. Ask for Thursday Total
7. Ask for Friday Total
8. Ask for Saturday Total
9. Do this Math: Grand Total = Sunday Total + Monday Total +
Tuesday Total + Wednesday Total + Thursday Total + Friday Total + Saturday Total
11. Do this Math: Dealership Average = Grand Total/ number of
days
11. Output: The weekly total is "Grand Total"
12. Output: The daily average is "dealership Average"
How did we get the human algorithm? Well we simply rewrite the problem statement:
| Problem Statement | Human Algorithm |
| Assignment | |
| Number of days = 7 | 1. number of days = 7 |
| Input: | |
| 1. Sunday Total | 2. Ask for Sunday Total |
| 2. Monday Total | 3. Ask for Monday Total |
| 3. Tuesday Total | 4. Ask for Tuesday Total |
| 4. Wednesday Total | 5. Ask for Wednesday Total |
| 5. Thursday Total | 6. Ask for Thursday Total |
| 6. Friday Total | 7. Ask for Friday Total |
| 7. Saturday Total | 8. Ask for Saturday Total |
| Calculations: | |
| 1. Grand Total = Sunday Total + Monday Total + Tuesday Total + Wednesday Total + Thursday Total + Friday Total + Saturday Total | 9. Do this Math: Grand Total = Sunday Total + Monday Total + Tuesday Total + Wednesday Total + Thursday Total + Friday Total + Saturday Total |
| 2. Dealership Average = Grand Total/ numberofdays | 10. Do this Math: Dealership Average = Grand Total/ numberofdays |
| Output: | |
| 1. The weekly total is "Grand Total" | 11. Output: The weekly total is "Grand Total" |
| 2. The daily average is "dealership Average" | 12. Output: The daily average is "dealership Average" |
How did we get the Flow Chart? Well we simply rewrite the human algorithm:
Click the button or the link to see videos on how this was done (Note: you
might see some slight differences in the video and what is on the page.
That's because it's very easy to change the text but very difficult to change
the video. The text on the page is always the better of the two for that
reason):
| Human Algorithm | Flow Chart
|
| 1. numberofdays = 7 | |
| 2. Ask for Sunday Total | |
| 3. Ask for Monday Total | |
| 4. Ask for Tuesday Total | |
| 5. Ask for Wednesday Total | |
| 6. Ask for Thursday Total | |
| 7. Ask for Friday Total | |
| 8. Ask for Saturday Total | |
| 9. Do this Math: Grand Total = Sunday Total + Monday Total + Tuesday Total + Wednesday Total + Thursday Total + Friday Total + Saturday Total | |
| 10. Do this Math: Dealership Average = Grand Total/ numberofdays | |
| 11. Output: The weekly total is "Grand Total" | |
| 12. Output: The daily average is "dealership Average" |
Now we have to write our code. Where do we get that from? Well, we get it from the flowchart. Each symbol on the flowchart is a line of code in our program:
| Flow Chart | Visual Basic code |
![]() |
numberofdays = 7 |
| suntotal = inputbox("What is Sunday's Total?") | |
| montotal = inputbox("What is Monday's Total?") | |
| tuestotal = inputbox("What is Tuesday's Total?") | |
| wedtotal = inputbox("What is Wednesday's Total?") | |
| thurtotal = inputbox("What is Thursday's Total?") | |
| fritotal = inputbox("What is Friday's Total?") | |
| sattotal = inputbox("What is Saturday's Total?") | |
| grandtotal = cint(Suntotal) + montotal + tuestotal + wedtotal + thurtotal + fritotal + sattotal | |
| dealershipaverage = grandtotal/numberofdays | |
| Document.write "The weekly total is " & grandtotal | |
| Document.write "<br> The weekly average is " & dealershipaverage |
<script language="vbscript">
Option Explicit
Dim Suntotal, montotal, tuestotal, wedtotal, thurtotal, fritotal, sattotal
Dim grandtotal, dealershipaverage, numberofdays
numberofdays = 7
suntotal = inputbox("What is Sunday's Total?")
montotal = inputbox("What is Monday's Total?")
tuestotal = inputbox("What is Tuesday's Total?")
wedtotal = inputbox("What is Wednesday's Total?")
thurtotal = inputbox("What is Thursday's Total?")
fritotal = inputbox("What is Friday's Total?")
sattotal = inputbox("What is Saturday's Total?")
grandtotal = cint(Suntotal) + montotal + tuestotal + wedtotal + thurtotal +
fritotal + sattotal
dealershipaverage = grandtotal/numberofdays
Document.write "The weekly total is " & grandtotal
Document.write "<br> The weekly average is " & dealershipaverage
</script>
We always place our constants at the beginning of our code. This way if the dealership decided to always close on Sunday then we very easily fix our code by changing the 7 to a 6 at the top of the code and everything works perfectly. Doesn't seem to be much of a savings of effort but imagine if there were a dozen constants and they were used in dozens of places in a thousand lines of code. Then you would be happy that the constants were declared at the beginning of the code when those values are changed.