Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, im currently working on a project to create a menu driven program only using coding in visual basic console application. I'm stuck on creating the quadratic solver as im unsure on how to start.
Im stuck on the quadratic equation part, any help will be appreciated thank you

What I have tried:

Module Module1

Sub Main()
Dim Choice As String
' Keep asking until the user enters one of the following options. (Data Validation).  
Do
' Prompt...

Console.WriteLine("CS0002")
Console.WriteLine("********************************************************************")
Console.WriteLine("Main Menu")
Console.WriteLine("1.Accuracy Decision")
Console.WriteLine("2.Quadratic equation")
Console.WriteLine("3.Monte-Carlo Integration")
Console.WriteLine("4.Prime number decider")
Console.WriteLine("5.Exit" & vbNewLine)
Console.WriteLine("Please select an option from 1-5:")

' Menu is created by console.writeline statements'


' Read a key. ReadKey returns a ConsoleKeyInfo value.  
Dim key As ConsoleKeyInfo = Console.ReadKey
' ConsoleKeyInfo contains information about the key pressed.  
' KeyChar gets the character for the key pressed.   
' If the user pressed 1-5 then they proceed to the next step
' value to usersChoice...  
Select Case key.KeyChar
Case "1"
Call Accuracy()
Case "2"
Call quadratic()
Case "3"
Call Monte()
Case "4"
Call Prime()
Case "5"

Exit Do
End Select
Console.WriteLine()
Console.WriteLine("Press any key to return to the menu...")
Choice = Console.ReadKey(True).KeyChar()
Loop
End Sub
Sub Accuracy()
Console.WriteLine("Feauture not implemented")
End Sub

Sub quadratic()

Dim a, b, c, det As Integer
Dim root1, root2 As Single
Dim numroot As Integer
Posted
Updated 10-Apr-18 2:38am
v2

1 solution

Is is just a matter of
  • Translate mathematical formulas into Visual Basic expressions
  • Use an if chain on the discriminant value

e.g.
VB
det = b * b - 4 * a * c
If det < 0 Then
  ' handle complex conjugates roots
ElseIf  det = 0 Then
  ' handle one real root
Else
  ' handle two real roots
End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900