You are to create an interactive program to calculate the area of some spherical
ID: 3685808 • Letter: Y
Question
You are to create an interactive program to calculate the area of some spherical shapes;specifically a circle, a sphere and a cylinder. The two inputs are the radius and the height. If the height is zero you are to calculate the area of a circle and a sphere. If the height is greater than zero than you are to calculate only the area of a cylinder.
create three functions one for each area of the shape. A subroutine should be written to enter the radius and height. Three additional subroutines should be written to display the area of each shape.
Another function should be written for setting a variable called anotherRun. This variable should be error checked to allow only for a 'n' or 'N' or 'y' or 'Y'.
Additionally, the radius should be constrained between 1 and 50 and the height should be constrained between 1 and 100.
A console-based application is required, im using visual studio 2015, Code: Visual basic
I think I have it working but it keeps zeroing out when the program runs, can someone help rewrite the program to make it work, if it has to be redone feel free to do so please.
Module Module1
Public r, h As Integer
Sub getdata()
While (True)
Dim r As Single
Console.WriteLine("Enter Radius")
r = Convert.ToInt32(Console.ReadLine())
If r > 0 And r < 51 Then
Exit While
End If
End While
While (True)
Dim h As Single
Console.WriteLine("Enter Height")
h = Convert.ToInt32(Console.ReadLine())
If h > 0 And h < 101 Then
Exit While
End If
End While
End Sub
Sub cirarea()
Dim a As Single
Dim r As Single
a = r * r * 3.142
Console.WriteLine("Area of Circle is = " & a)
End Sub
Sub spearea()
Dim a As Single
Dim r As Single
a = r * r * 3.142 * 4
Console.WriteLine("Area of Sphere is = " & a)
End Sub
Sub cylarea()
Dim a As Single
Dim h As Single
Dim r As Single
a = (r * r * 3.142 * 2) + (a * 3.142 * r * h)
Console.WriteLine("Area of Cylinder is = " & a)
End Sub
Sub Main()
getdata()
cirarea()
spearea()
cylarea()
Console.ReadKey()
End Sub
End Module
Explanation / Answer
Hi, Your program is perfect :) But you have made only one error. You have re-=defined r and h everywhere again. We need to declare it only once at global level. Here is the running code:
Module Module1
Public r, h As Integer
Sub getdata()
While (True)
Console.WriteLine("Enter Radius")
r = Convert.ToInt32(Console.ReadLine())
If r > 0 And r < 51 Then
Exit While
End If
End While
While (True)
Console.WriteLine("Enter Height")
h = Convert.ToInt32(Console.ReadLine())
If h > 0 And h < 101 Then
Exit While
End If
End While
End Sub
Sub cirarea()
Dim a As Single
a = r * r * 3.142
Console.WriteLine("Area of Circle is = " & a)
End Sub
Sub spearea()
Dim a As Single
a = r * r * 3.142 * 4
Console.WriteLine("Area of Sphere is = " & a)
End Sub
Sub cylarea()
Dim a As Single
a = (r * r * 3.142 * 2) + (a * 3.142 * r * h)
Console.WriteLine("Area of Cylinder is = " & a)
End Sub
Sub Main()
getdata()
cirarea()
spearea()
cylarea()
Console.ReadKey()
End Sub
End Module
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.