In: Computer Science
in BASIC language, i need to make function smallMiles(size) display the smallest number in the MilesDriven array . here is my code so far:
size =1
Dim Monthname$(size)
Dim MilesDriven(size)
do
print "Enter your choice from this menu."
print "Enter 'P' to enter miles and month,OR"
print "Enter 'S' to search for month. OR,"
print "Enter 'M to search month with smallest miles. OR,"
print "Enter 'L' to search for month with largest miles. OR,"
print "Enter 'E' to exit."
input choice$
select case (choice$)
case "P","p"
res= collectData(size)
case "S","s"
res = search(size)
case "M","m"
res = smallMiles(size)
case "L","l"
res = largeMiles(size)
case "E","e"
print "Have a nice day.Goodbye."
case else
print "Invalid choice, please try again"
print
end select
loop until (choice$ = "E" or choice$ = "e" )
function collectData(size)
for position= 0 to size
print "Enter miles."
input MilesDriven(position)
print "Enter month."
input Monthname$(position)
next
end function
function search(size)
print "Enter month."
input month$
for position = 0 to size
if(month$ = Monthname$(position))then
print "The month is: ";Monthname$(position)
print "The number of miles driven is: ";MilesDriven(position)
exit for
end if
next
end function
function smallMiles(size)
print "Enter month."
input month$
for position = 0 to size
smallest = MilesDriven(position)
if (month$ = Monthname$(position))then
if (MilesDriven(position) < smallest )then
smallest = MilesDriven(position)
end if
print "The month with smallest miles driven is:
";Monthname$(position)
print "The smallest miles driven is: ";smallest
exit for
end if
next
end function
Dim Monthname$(12)
Dim MilesDriven(12)
do
response$=displaymenu$()
select case
case "P", "p"
res=populatearray(BYREF Monthname$,BYREF MilesDriven)
case "S", "s"
res=searchmonth$(BYREF Monthname$,BYREF MilesDriven)
case "M", "m"
res=smallestmiles(BYREF Monthname$,BYREF MilesDriven)
case "L", "l"
res=largestmiles(BYREF Monthname$,BYREF MilesDriven)
case else
print "Invalid Choice"
end select
loop until response$="E" or response$="e"
function displaymenu$()
print "Enter P to populate miles"
print "Enter S search for month"
print "Enter M search for month name with smallest miles"
print "Enter L to search for month name with largest miles"
print "Enter E to exit the program"
input choice$
displaymenu$=choice$
end function
function populatearray(BYREF Monthname$,BYREF MilesDriven)
for monthcount = 1 to 12
print "enter month name"
input Monthname$(monthcount)
print "enter miles driven"
input MilesDriven(monthcount)
end function
function searchmonth$(BYREF Monthname$,BYREF MilesDriven)
print "Please the name of a month ";
input nameofmonth$
for pos=1 to 12
if nameofmonth$ = Monthname$(pos) then
print "Month name is "; Monthname$(pos)
print "Miles driven is "; MilesDriven(pos)
end function
function smallestmiles(MilesDriven)
smallestmiles=MilesDriven(1)
for pos=1 to 12
if MilesDriven(pos) < smallestmiles then
smallestmiles=MilesDriven(pos)
print "Smallest driven is "; MilesDriven(pos)
end function
function largestmiles(MilesDriven)
largestmiles=MilesDriven(1)
for pos=1 to 12
if MilesDriven(pos) < largestmiles then
largestmiles=MilesDriven(pos)
print "Largest driven is "; MilesDriven(pos)
end function