ok i have a unit project and am really stumped. i want to make a really good, working program and it has to be in vb.net, and it has to be a console application (the "Module - Sub Main() - End Sub - End Module" kind of program). it needs to ask the user to input the values for the 3 sides of a cube and then say that it is going to calculate the volume of the cube and then say "&variable& is the volume of your cube". i really need help and a place to start - any help?

Dani AI

Generated

The original task asked for a VB.NET console program that accepts three side lengths and prints the volume. Important clarification: a cube has all sides equal, so one side is enough; three distinct inputs describe a rectangular prism (length × width × height). requested the Module/Sub Main structure; correctly pointed to creating a Console Application; 's recommendation to review early chapters on I/O and types is a solid foundation.

A simple, robust pattern is: prompt for each side, parse with Double.TryParse to avoid exceptions, validate positive values, compute volume = s1 * s2 * s3, then print the result. The sample below labels the result "cube" when all sides match (using a small tolerance), otherwise "rectangular prism."

Option Strict On

Module Program
    Sub Main()
        Dim s1, s2, s3 As Double

        Console.WriteLine("Enter side 1:")
        While Not Double.TryParse(Console.ReadLine(), s1) OrElse s1 <= 0
            Console.WriteLine("Invalid input. Enter a positive number for side 1:")
        End While

        Console.WriteLine("Enter side 2:")
        While Not Double.TryParse(Console.ReadLine(), s2) OrElse s2 <= 0
            Console.WriteLine("Invalid input. Enter a positive number for side 2:")
        End While

        Console.WriteLine("Enter side 3:")
        While Not Double.TryParse(Console.ReadLine(), s3) OrElse s3 <= 0
            Console.WriteLine("Invalid input. Enter a positive number for side 3:")
        End While

        Dim volume As Double = s1 * s2 * s3
        Dim tol As Double = 1E-9
        Dim shape As String = If(Math.Abs(s1 - s2) < tol AndAlso Math.Abs(s1 - s3) < tol, "cube", "rectangular prism")

        Console.WriteLine(volume.ToString() & " is the volume of the " & shape & ".")
        Console.WriteLine("Press Enter to exit.")
        Console.ReadLine()
    End Sub
End Module

Troubleshooting notes: prefer TryParse over direct conversion to avoid runtime errors; watch culture-specific decimal separators if tests involve decimals; compare doubles with a tolerance rather than exact equality. If the assignment expects integers, switch to Integer.TryParse.

Recommended Answers

All 2 Replies

Start by opening your copy of Visual Studio or Visual Basic Express. Click on "Create Project" and choose "Console Application." Give it a descriptive name. Once you've gotten this far, type some code, then come back and post it if you've got more questions.

commented: Sounds like a reasonable start to me. +10

Open the prescribed text on VB programming for whatever course you are on at chapter one

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.