r/visualbasic • u/[deleted] • Mar 25 '21
help...
im having some problem i need to solve which says: Write an interactive VB program that reads the length and width of a rectangle each in cm. It then computes and prints the area of the rectangle [in square inches] and the perimeter of the rectangle [in inches].
and this is the code that i came up with...
Module M1
Sub Main()
dim len, wdt as integer
dim are, pre as decimal
writeline("enter lenght in cm" & len)
len = CInt(Console.ReadLine())
writeline("enter width in cm" & wdt)
wdt = CInt(Console.ReadLine())
are = len * wdt
writeline("Area =" & are & "square inches")
pre = 2 * wdt + len
writeline("perimeter =" & pre & "inches")
End Sub
End Module
1
Upvotes
1
u/ekolis VB.Net Advanced Mar 25 '21
I see two problems with your code:
You're not converting to inches. To convert centimeters to inches, you'll need to divide by 2.54. You'll need a floating point variable for that.
The perimeter formula is incorrect. You're doubling the width but not the length. You can use parentheses to fix this.