Question

In: Computer Science

in BASIC language, i need to make function smallMiles(size) display the smallest number in the MilesDriven...

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

Solutions

Expert Solution

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





Related Solutions

Hello! I need to add a method that will display the total number of times the...
Hello! I need to add a method that will display the total number of times the user answered the question correctly, how many time he was right or wrong and the percentage of time they were correct in answering. import java.util.Random; import java.util.Scanner; public class Test { private static int getUserInput() { int n; Scanner scanner = new Scanner(System.in); n = scanner.nextInt(); return n; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String choice = "Yes";...
I need the vhdl code to display the binary number specified by an 8 input dip...
I need the vhdl code to display the binary number specified by an 8 input dip switch on a 7 segment display.
I need to write a function that counts the number of total wins and losses. I...
I need to write a function that counts the number of total wins and losses. I have a text file called analysis_data.txt with 1000 lines written Won Loss Won Loss Won Won ... The function need to do the following: Opens the analysis_data.txt file and reads through all the data, counting number of 'Won' and 'Loss' words stored in the file. Returns two integers: count of wins and count of losses from the text file. **Can't use the break statement
In MIPS assembly language, write a function that will display the max and min value in...
In MIPS assembly language, write a function that will display the max and min value in an array. Then write a function to calculate and display the average of all values in an array. This must be done in MIPS assembly language.
Hello I need a small fix in my program. I need to display the youngest student...
Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...
We need to create basic program that will simply display a menu and allow the user...
We need to create basic program that will simply display a menu and allow the user to select one of the choices. The menu should be displayed such that each option will be numbered, as well as have one capital letter so as to indicate that either the number or the designated letter can be entered to make their choice. Once the choice is made, the sub-menu for that selection should be displayed. Colors with an odd number of letters...
In C++ Write a function that took in SIZE and array [size] and counted the number...
In C++ Write a function that took in SIZE and array [size] and counted the number of elements >100
How can I make my own function for rbinom(n, size, prob) in R. So, basically I...
How can I make my own function for rbinom(n, size, prob) in R. So, basically I want to build my own rbinom function that gives me the same result as rbinom that's built in R software.
Use Visual Basic Language In this assignment you will need to create a program that will...
Use Visual Basic Language In this assignment you will need to create a program that will have both a “for statement” and an “if statement”. Your program will read 2 numbers from the input screen and it will determine which is the larger of the 2 numbers. It will do this 10 times. It will also keep track of both the largest and smallest numbers throughout the entire 10 times through the loop. An example of the program would be...
Let's assume that, an application program calls a High Level Language library function to display a...
Let's assume that, an application program calls a High Level Language library function to display a string with red color in the monitor. Explain the steps executing the operation (from function call to low hardware level).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT