Question

Visual Basic: Write the code for a function named GetMajor. The function should prompt the user...

Visual Basic:
Write the code for a function named GetMajor. The function should prompt the user to enter a major field of study and then return the user’s response. Then write a statement to invoke the GetMajor function, returning the result to the strCurrentMajor variable.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Copy and paste the code in your compiler and the results are as expected..... syntax varies according to compiler ... try as your comipler works .... i have executed the code in online compiler...

-------------------------------------------------------------------------------------------

CODE ::

public class compiler
shared function Main as integer ' main function in visual basic
  
Dim strCurrentMajor As String 'declare the variable as STRING type
strCurrentMajor = GetMajor() 'invoking GetMajor function and returned result is stored in strCurrentMajor variable
Console.WriteLine ("Current Major entered by User is : " &strCurrentMajor) 'display the user's response returned from the function
return 0
End function


shared Function GetMajor() As String ' a GetMajor function of returning type STRING...its a shared function that is, its visible to other functions
Console.WriteLine("Enter your Major field of Study : ")
Dim input = Console.ReadLine() ' prompt the user to enter a major
Return input ' returns the users response to the invoked function call
End Function
  
end class

-------------------------------------------------------------------------------------------------------------

Share 0 1 public class compiler 2 shared function Main as integer main function in visual basic Dim strCurrentMajor As String

INPUT :: In online compier ... input need to be given in Input tab of the output window ... depends on your compiler ... if you are using console based compiler then the user can enter input through console

Output Build error Input Comments0 Biology

OUTPUT ::

Output Build error Input Comments 0 Enter your Major field of Study Current Major entered by User is Biology

Add a comment
Know the answer?
Add Answer to:
Visual Basic: Write the code for a function named GetMajor. The function should prompt the user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT