RSS Forums RSS
Please support our VB.NET advertiser: Programming Forums

vb.net NEWBIE!! Triangle problem!!

Join Date: Feb 2006
Posts: 2
Reputation: jacjr is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jacjr jacjr is offline Offline
Newbie Poster

Re: vb.net NEWBIE!! Triangle problem!!

  #3  
Apr 30th, 2006
Originally Posted by jacjr
Hello to everyone! I have just started taking what is described as a beginning Visual Basic.Net class. I have no programming knowledge, except my class time which started mid January.
Right now I'm trying to figure out how to give a type of triangle(equilateral, scalene, or isosceles) and the shortest side of the triangle. We have been talking about relational, logical operators, If, Else statements.

I am thoroughly conflabbergasted at this point. Our text we are using, "Microsoft Visual Basic .Net Programming: problem analysis to design" , by E. Reed Doak, doesn't really seem to be beginner friendly. Am looking for suggestions on other text for BEGINNERS!

Here is the code I've managed in about3 hours work on this problem:

Module TriangleTypes
Sub Main()
:o
'
' Declare variables
Dim strTriangle As String
Dim intSide1, intSide2, intSide3 As Integer
'
' Ask for user Input
'
Console.Write("Enter length of side 1 of a triangle as an integer: ")
intSide1 = Convert.ToInt32(Console.ReadLine())
Console.WriteLine()
Console.Write("Enter length of side 2 of a triangle as an integer: ")
intSide2 = Convert.ToInt32(Console.ReadLine())
Console.WriteLine()
Console.Write("Enter length of side 3 of a triangle as an integer: ")
intSide3 = Convert.ToInt32(Console.ReadLine())
Console.WriteLine()
'
If intSide1 = intSide2 Then
strTriangle = "Equilateral"
Else
If intSide1 = intSide3 Then
strTriangle = "Equilateral"
Else
If intSide2 = intSide3 Then
strTriangle = "Equilateral"
Else
If intSide1 <> intSide2 Then




End If

End If
End If

Console.WriteLine("Your triangle type is: {0}", strTriangle)

ANY Help would be appreciated.
thanks,
jacjr (back to school at 40!)




Figured it out thanks for the help:

Dim strTriangle As String
Dim intSide1, intSide2, intSide3 As Integer
Dim intShortSide As Integer
'
' Ask for user Input
'
Console.Write("Enter length of side 1 of a triangle as an integer: ")
intSide1 = Convert.ToInt32(Console.ReadLine())
Console.WriteLine()
Console.Write("Enter length of side 2 of a triangle as an integer: ")
intSide2 = Convert.ToInt32(Console.ReadLine())
Console.WriteLine()
Console.Write("Enter length of side 3 of a triangle as an integer: ")
intSide3 = Convert.ToInt32(Console.ReadLine())
Console.WriteLine()
'
' find type of triangle
If intSide1 = intSide2 And intSide2 = intSide3 Then
strTriangle = "Equilateral"
Console.WriteLine("Your triangle type is: {0}", strTriangle)
Console.WriteLine()
Else
If intSide1 = intSide2 Or intSide3 = intSide2 Or intSide1 = intSide3 Then
strTriangle = "Isosceles"
Console.WriteLine("Your triangle type is: {0}", strTriangle)
Console.WriteLine()
Else
If intSide1 <> intSide2 And intSide1 <> intSide3 And intSide2 <> intSide3 Then
strTriangle = "Scalene"
Console.WriteLine("Your triangle type is: {0}", strTriangle)
'
' give shortest side
If intSide1 < intSide2 Then
intShortSide = intSide1
Else
intShortSide = intSide2
End If
If intSide3 < intShortSide Then
intShortSide = intSide3
End If
End If
End If
End If
Console.WriteLine()
Console.WriteLine("The shortest side has a length of {0}. ", intShortSide)
Console.WriteLine()

End Sub

End Module
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 6:59 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC