-
Lenguaje
Visual Basic .Net
-
Descripción
Se requiere utilizar una calculadora que pueda realizar operaciones básicas como lo son: suma, resta, multiplicación, división o residuo, para esto se reciben 3 números, el primer número representa al valor 1, el segundo el valor 2 y el último represente la opción del usuario; se deberá mostrar el resultado final de la operación así como la opción elegida.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Module SumaRestaMultiplicacionDivisionOResiduo
Sub Main()
Dim a, b, operacion, resultado_final As Integer
Console.Write("Ingresa el valor de a: ")
a = Integer.Parse(Console.ReadLine())
Console.Write("Ingresa el valor de b: ")
b = Integer.Parse(Console.ReadLine())
Console.WriteLine("Selecciona el valor de operacion.")
Console.WriteLine(vbTab & "1.- Suma")
Console.WriteLine(vbTab & "2.- Resta")
Console.WriteLine(vbTab & "3.- Multiplicaci" & ChrW(&HF3) & "n")
Console.WriteLine(vbTab & "4.- Divisi" & ChrW(&HF3) & "n")
Console.WriteLine(vbTab & "5.- Residuo")
Console.Write(vbTab & ": ")
Do
operacion = Integer.Parse(Console.ReadLine())
If operacion < 1 Or operacion > 5 Then
Console.Write("Valor incorrecto. Ingrésalo nuevamente.: ")
End If
Loop While operacion < 1 Or operacion > 5
resultado_final=0
If operacion = 1 Then
resultado_final=a+b
Console.WriteLine("Suma")
End If
If operacion = 2 Then
resultado_final=a-b
Console.WriteLine("Resta")
End If
If operacion = 3 Then
resultado_final=a*b
Console.WriteLine("Multiplicaci" & ChrW(&HF3) & "n")
End If
If operacion = 4 And b = 0 Then
Console.WriteLine("No se puede obtener la divisi" & ChrW(&HF3) & "n")
End If
If operacion = 4 And b <> 0 Then
resultado_final=a/b
Console.WriteLine("Divisi" & ChrW(&HF3) & "n")
End If
If operacion = 5 And b = 0 Then
Console.WriteLine("No se puede obtener el residuo")
End If
If operacion = 5 And b <> 0 Then
resultado_final=a Mod b
Console.WriteLine("Residuo")
End If
Console.WriteLine("Valor de resultado final: " & resultado_final)
Console.WriteLine()
Shell ("cmd /c pause", AppWinStyle.NormalFocus, True)
End Sub
End Module
Sub Main()
Dim a, b, operacion, resultado_final As Integer
Console.Write("Ingresa el valor de a: ")
a = Integer.Parse(Console.ReadLine())
Console.Write("Ingresa el valor de b: ")
b = Integer.Parse(Console.ReadLine())
Console.WriteLine("Selecciona el valor de operacion.")
Console.WriteLine(vbTab & "1.- Suma")
Console.WriteLine(vbTab & "2.- Resta")
Console.WriteLine(vbTab & "3.- Multiplicaci" & ChrW(&HF3) & "n")
Console.WriteLine(vbTab & "4.- Divisi" & ChrW(&HF3) & "n")
Console.WriteLine(vbTab & "5.- Residuo")
Console.Write(vbTab & ": ")
Do
operacion = Integer.Parse(Console.ReadLine())
If operacion < 1 Or operacion > 5 Then
Console.Write("Valor incorrecto. Ingrésalo nuevamente.: ")
End If
Loop While operacion < 1 Or operacion > 5
resultado_final=0
If operacion = 1 Then
resultado_final=a+b
Console.WriteLine("Suma")
End If
If operacion = 2 Then
resultado_final=a-b
Console.WriteLine("Resta")
End If
If operacion = 3 Then
resultado_final=a*b
Console.WriteLine("Multiplicaci" & ChrW(&HF3) & "n")
End If
If operacion = 4 And b = 0 Then
Console.WriteLine("No se puede obtener la divisi" & ChrW(&HF3) & "n")
End If
If operacion = 4 And b <> 0 Then
resultado_final=a/b
Console.WriteLine("Divisi" & ChrW(&HF3) & "n")
End If
If operacion = 5 And b = 0 Then
Console.WriteLine("No se puede obtener el residuo")
End If
If operacion = 5 And b <> 0 Then
resultado_final=a Mod b
Console.WriteLine("Residuo")
End If
Console.WriteLine("Valor de resultado final: " & resultado_final)
Console.WriteLine()
Shell ("cmd /c pause", AppWinStyle.NormalFocus, True)
End Sub
End Module