저는 초급 프로그래머입니다. 나는 고등학교에서 수업 중 하나로서 프로그래밍 강좌를 수강해야하므로, 많이 이해하지 못하게하기 위해 최선을 다하고 있습니다. 그 말로는 제발 쉬워 져요.내 코드에서 Try, Catch 및 Finally를 사용하는 방법을 알아야합니까?
프로젝트의 경우 이전 할당을 위해 만든 두 개의 프로그램, 산술 시퀀스를 결정하는 프로그램 및 큐브 또는 구의 볼륨을 계산하기위한 프로그램으로 돌아 가야합니다.
첫 번째 지침은 모든 변수를 정의하도록 사용자에게 묻도록 프로그램을 작성하는 것입니다. 예를 들어, 프로그램은 사용자에게 한면의 길이 또는 Cube and Sphere 프로그램의 반경 값을 입력하도록 요청합니다.
나는 프로그램을 작성할 때 이미 이것을했다고 믿지만 두 번째 방향 설정에 어려움을 겪고 있습니다. "키워드를 시도하고 잡아서 마지막으로 포함 시키며, 제대로 작동하게하십시오. 사용자가 불가능한 계산을 정의하면 표시된 오류 메시지가 있어야하며 그렇지 않은 경우 단순히 대답을 표시하는 경우에도 오류가 없음을 나타내는 조치가 있어야합니다. ").
나는이 코드를 내 코드에 넣는 법을 정말로 모른다. 누군가가 내 코드에서 설명하거나 설명해 줄 수 있다면 정말 고맙겠습니다. 여기에 내 코드 : 큐브의
볼륨 또는 구체
Sub Main()
Dim Type As String
Dim Size As String
Dim Length_Radius As Double
Dim Output As Double
Dim Value As Double
Console.WriteLine("Would you like to calculate the volume of a (C)ube or a (S)phere? *press either C or S then enter to continue*")
Type = Console.ReadLine
Type = Convert.ToString(Type)
Value = Asc(Type)
If (Value = 67) Or (Value = 99) Then
Console.WriteLine("The equation is x^3 where x is the length of a side. What would you like the value of x to be?")
Size = Console.ReadLine
Length_Radius = Convert.ToDouble(Size)
Output = (Length_Radius * Length_Radius * Length_Radius)
Console.WriteLine("The value of the volume of the Cube is: " & Output & ".")
ElseIf (Value = 83) Or (Value = 115) Then
Console.WriteLine("The equation is 4/3*pi*r^3 where r is the radius. What would you like the value of the radius to be?")
Size = Console.ReadLine
Length_Radius = Convert.ToDouble(Size)
Output = ((4/3) * 3.14 * (Length_Radius * Length_Radius * Length_Radius))
Console.WriteLine("The value of the volume of a sphere is: " & Output & ".")
ElseIf (Value <> 83) Or (Value <> 115) Or (Value <> 67) Or (Value <> 99) Then
Console.WriteLine("You have inputted an incorrect value.")
End If
Console.ReadLine()
End Sub
산술 순서
Sub Main()
Dim Letters As String
Dim a_n, d, a_one As Double
Dim Output As Double
Console.WriteLine("This program will perform the arithmetic sequence (a(n) = a(1) + d(a(n) - 1)")
Console.WriteLine("What would you like the value of 'a(n)' to be? *The total number of times the sequence will repeat.*")
Letters = Console.ReadLine
a_n = Convert.ToDouble(Letters)
Console.WriteLine("What would you like the value of 'a(1)' to be? *The starting value.*")
Letters = Console.ReadLine
a_one = Convert.ToDouble(Letters)
Console.WriteLine("What would you like the value of 'd' to be? *The number that the equation is multiplied by*")
Letters = Console.ReadLine
d = Convert.ToDouble(Letters)
Output = (a_one + d * (a_n - 1))
Console.WriteLine("The value of the arithmetic sequence is: " & Output & ".")
Console.ReadLine()
End Sub
마침내 try, catch에 대한 설명서를 읽었습니까? – JohnFx
문서로 당신이 실제로 Try, Catch, Finally가 무엇인지 배웠다면, 나는 주어진 수업에서 그들에 대해 조금 배웠다. 그러나 나는 프로그래밍을 이해할 수없는 것 같다. – user3192348
설명서에서 몇 가지 예제를 시도해 보셨습니까? – JohnFx