If Anidado
Hola, aquà les dejo el programa Concierto usando entradas: VIPORO, VIPPLATA, VIPBRONCE.
Este es un ejemplo de IF ANIDADO, en donde habrán “secuencias IF” dentro de otras “secuencias IF”.
Codigo de la Clase:
Archivo: pago.cs (usen otro nombre).
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | using System; using System.Collections.Generic; using System.Text; namespace WindowsAppConciertoIFanidados { public class pago { int edad; int monto; public int Pago(string zona, string eda) { edad = int.Parse(eda); if (zona == "VIPORO") { if(edad<18) { monto=100; } else { monto=150; } } else { if (zona == "VIPPLATA") { if(edad<18) { monto=64; } else { monto=95; } } else { if (zona == "VIPBRONCE") { if(edad>=60) { monto=10; } else { monto=50; } } } } return monto; } public string Mostrar(double x) { string Salida = ""; Salida += "Debido a su edad ( " + edad + " años ) n"; Salida += "El Monto a pagar es de:nn"; Salida += "---> S./" + x + " Nuevos Soles."; return Salida; } } } |
Codigo Del Formulario:
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 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsAppConciertoIFanidados { public partial class Form1 : Form { public Form1() { InitializeComponent(); } pago obj = new pago(); private void btnCalcular_Click(object sender, EventArgs e) { double x; x = obj.Pago(txtNum1.Text, txtNum2.Text); lblResultado.Text = obj.Mostrar(x); } private void btnLimpiar_Click(object sender, EventArgs e) { txtNum1.Clear(); txtNum2.Clear(); lblResultado.Text = ""; txtNum1.Focus(); } private void btnSalir_Click(object sender, EventArgs e) { Application.Exit(); } } } |
Eso es todo.
